Skip to content

Streaming merger: delegate to DuckDB (11.5x faster at high cardinality) - #34

Merged
cigrainger merged 1 commit into
mainfrom
perf/streaming-merger-duckdb
Mar 25, 2026
Merged

cigrainger merged 1 commit into
mainfrom
perf/streaming-merger-duckdb

Conversation

@cigrainger

Copy link
Copy Markdown
Contributor

Summary

Replace the Elixir-side lattice folding in StreamingMerger with DuckDB SQL re-aggregation. The streaming merger now:

  1. fold/2 — collects IPC binaries (no processing)
  2. to_dux/1 — delegates to the batch Merger.merge_to_dux/2 which already has correct re-aggregation SQL

Removed ~60 lines of Elixir map manipulation (extract_group_key, init_group, merge_row, Map.put per row). The Lattice classification is still used for the streamability check.

Benchmark (2 workers, 100K rows)

Groups Before (median) After (median) Speedup
100 84ms 54ms 1.6x
10,000 716ms 62ms 11.5x

The 10K group case was bottlenecked on Elixir Map.put per row — DuckDB handles it trivially with a GROUP BY.

Test plan

  • 28 streaming merger tests pass (0 failures)
  • Credo strict clean
  • Benchmarks before and after

🤖 Generated with Claude Code

…ding

Replace Elixir map-based lattice folding with DuckDB SQL re-aggregation.
fold/2 now collects IPC binaries; to_dux/1 delegates to the batch
Merger which already has the correct re-aggregation SQL.

Simpler code (removed 60 lines of Elixir merge logic), same correctness
guarantees, and dramatically better performance at high group cardinality.

Benchmark (2 workers, 100K rows):
  100 groups: 84ms → 54ms (1.6x)
  10K groups: 716ms → 62ms (11.5x)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cigrainger
cigrainger merged commit a1d17c0 into main Mar 25, 2026
5 checks passed
@cigrainger
cigrainger deleted the perf/streaming-merger-duckdb branch March 25, 2026 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant