perf(graph): batch BulkLoad CSV / COPY FROM at 50k rows#143
Merged
Conversation
BulkLoadNodes and copyEdgeGroup previously staged one CSV with every row and issued a single Kuzu COPY FROM. Kuzu buffers the full CSV in process memory during ingest, so on polyglot targets with hundreds of thousands of nodes the COPY-side resident set grew unbounded. Chunk the work into batches of bulkLoadBatchSize (default 50k, override via CODEIQ_BULK_BATCH_SIZE env). Each batch stages + ingests + cleans up before the next batch starts so neither on-disk CSV nor Kuzu's ingest buffer ever holds more than batchSize rows. Caveat: this is production hygiene, not a complete OOM fix at the ~/projects/ scale (49k files / 434k nodes). At that scale the enrich pipeline OOMs earlier than BulkLoad - likely in the graph builder / linker / classifier passes that materialise all nodes in Go memory before BulkLoad runs. Streaming the upstream enrich stages is a separate, larger refactor. Cypher uniqueness constraints are still enforced cross-batch (Kuzu ingest commits before the next COPY starts), so a duplicate primary key surfaces the same Copy exception either way. Verified: - go test ./... -count=1 - 875 pass - fixture-minimal index->enrich->stats - same 45-node / 68-edge output
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
`BulkLoadNodes` and `copyEdgeGroup` previously staged one CSV with every row and issued a single Kuzu `COPY FROM`. Kuzu buffers the full CSV in process memory during ingest, so on polyglot targets with hundreds of thousands of nodes the COPY-side resident set grew unbounded.
This PR chunks the work into batches of `bulkLoadBatchSize` (default 50k, override via `CODEIQ_BULK_BATCH_SIZE` env). Each batch stages + ingests + cleans up before the next batch starts so neither on-disk CSV nor Kuzu's ingest buffer ever holds more than `batchSize` rows.
Caveat — partial fix
This is production hygiene, not a complete OOM fix at `~/projects/` scale (49k files / 434k nodes). At that scale the enrich pipeline OOMs earlier than BulkLoad — likely in the GraphBuilder / linker / classifier passes that materialise all nodes in Go memory before BulkLoad runs.
Reproducer:
```bash
codeiq index ~/projects/
codeiq enrich ~/projects/ # OOM at exit 137, ~46s in (before BulkLoad fires)
```
Streaming the upstream enrich stages is a separate, larger refactor — tracked as a follow-up.
Correctness
Cypher uniqueness constraints are still enforced cross-batch (Kuzu ingest commits before the next COPY starts), so a duplicate primary key surfaces the same Copy exception either way.
Test plan