perf: bound build memory and harden bulk graph updates#26
Merged
Conversation
Reuse versioned parse results and unresolved candidates during builds and updates. Batch flow traversal and reduce resolver allocation churn for large Kotlin corpora.
tae2089
marked this pull request as ready for review
July 16, 2026 08:18
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
implementsedges before staged call and reference edges, regardless of file or spool record orderTraceFlowfrontiers with batched graph reads instead of one query per visited node(namespace, file_path)resolver lookup index based on measured PostgreSQL query plansWhy
Large repositories previously retained too much deferred edge state during graph builds. Streaming that state lowers peak memory, but staged replay also needs a global dependency order: call resolution can depend on implementations discovered in later files.
Incremental updates have a related correctness boundary. Adding a new package can introduce implementations that restore or change edges from unchanged callers outside the changed-file set. The unresolved-candidate index records that dependency explicitly, allowing updates to revisit affected callers while retaining a safe full-build boundary when required.
PostgreSQL profiling exposed additional persistence bottlenecks after parsing was improved. Annotation writes performed per-annotation lookup, transaction, upsert, and tag replacement; file updates repeated the same deletion sequence per file; full graph deletion selected large node-ID sets; and resolver file lookups lacked an index matching their namespace-scoped predicate. The added bulk paths and indexes target those measured operations without adding connection-pool tuning or write goroutines.
Correctness behavior
TraceFlowpreserves depth, direction, cycle, and limit behavior while batching frontier readsreplace=falsewith include paths does not escape its requested scopePerformance
Build memory profile
Measured on the earlier large Kotlin corpus used to validate spool-backed edge streaming:
Current full-corpus CPU and allocation profile
Measured on a fresh SQLite database with 22,719 processed files, 114,582 nodes, and 751,148 parsed edges. Both sides used the same cold-parse-cache condition.
CommonSuffixDepthfell from two allocations per call to zero, andcollectJVMMembersFromTextcumulative allocation fell from 2.62 GiB to 82.93 MiB. The single-run process RSS did not improve; it includes Tree-sitter, SQLite, mappings, runtime, and process-level high-water variance, so this PR does not claim an RSS reduction from the allocation fixes.PostgreSQL persistence and resolver profile
The full greeting corpus completed with 22,719 files, 114,582 nodes, and 751,148 parsed edges after the bulk annotation path was added. A prior same-corpus run without annotation batching was stopped after 616.58 s without completing; the bulk candidate completed in 257.54 s wall time.
DeleteGraphfor 66,000 PostgreSQL nodesThe qualified-name lookup already completed the representative 500-name query in 11.3 ms with the existing index, so no additional index was added for that path. A populated 93,752-node greeting namespace rebuilt in 1m44s, and subsequent empty-corpus cleanup removed its nodes, edges, and search documents in 1.8 s without the earlier multi-minute search-document deletion stall.
Incremental update matrix
Measured on a pristine 1,592-file Kotlin corpus with isolated SQLite databases. The changed files were copied into a wholly new package, so
updateintentionally selected the correctness-preserving full-build fallback.As a control, adding 15 files to an existing package stayed incremental: 1.46 s update vs 14.57 s build, with zero graph differences. A later 100% comment-modify benchmark using bulk incremental deletion completed in 25.15 s versus 10.77 s for a fresh build, also with zero persisted graph differences.
Schema changes
text, matching SQLite and preserving oversized annotations(namespace, file_path)node index for resolver and namespace-scoped file readsValidation
Passed checks include:
CGO_ENABLED=1 go test -tags "fts5" ./... -count=1DeleteGraphwith 66,000 nodesccg build .,ccg docs --out docs, andccg lintgit diff --checkccg lintexits successfully with one pre-existing notice for the private helpergraphgorm.unresolvedIndexHash. The existing Tree-sitter Lua null-character compiler warning remains non-fatal and unchanged.