Repository navigation
Build graph adjacency in DuckDB instead of Elixir MapSets - #36
Merged
Merged
Conversation
Replace Elixir-side adjacency construction (materialize edge columns → Enum.zip → Enum.reduce with MapSet) with DuckDB LIST aggregation. DuckDB handles bidirectional edge expansion, deduplication, and grouping in a single SQL pass. Also fixes get_vertex_ids to use table_to_rows instead of table_to_columns for consistency. Adds bench/graph_bench.exs for betweenness centrality benchmarking. Performance is neutral — BFS iterations dominate at all tested scales. The adjacency build is ~5% of total time. The change simplifies code and delegates deduplication to DuckDB. Benchmark (10K vertices, ~80K edges, sample=10): Before: 806ms median After: 726ms median (~10% faster, within noise) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace Elixir-side adjacency construction for betweenness centrality with DuckDB
LIST(DISTINCT ...)aggregation.Before: Materialize all edge columns →
Enum.zipboth directions →Enum.reducebuilding%{node => MapSet.new(neighbors)}→MapSet.to_listeach entry.After: Single SQL query:
WITH bidir AS (... UNION ALL ...) SELECT node, LIST(DISTINCT neighbor) FROM bidir GROUP BY node→table_to_columns→Enum.zip |> Map.new.DuckDB handles bidirectional expansion, deduplication, and grouping in one pass. Simpler code, same correctness.
Also adds
bench/graph_bench.exsfor betweenness centrality benchmarking.Benchmark (10K vertices, ~80K edges, sample=10)
Performance neutral — BFS iterations dominate (~95% of time). The adjacency build improvement is masked by the algorithmic cost. The value is in code clarity and delegating deduplication to DuckDB.
Test plan
🤖 Generated with Claude Code