Repository navigation
fix(pipeline): free trees and compact results in sequential definitions pass - #2418
Conversation
…ns pass The sequential route (50 files or fewer, or CBM_WORKERS=1) cached each file's raw extraction result with its tree-sitter tree and uncompacted working arena for the rest of the run. Free the tree, compact the result and release the working arena exactly as the parallel worker already does; the cross-file LSP pass re-parses these files, as it always has on the parallel route. A 40-file repo of large Python files peaks at 246 MB instead of 962 MB; the graph is byte-identical. Signed-off-by: Nelson Spence <nelson@projectnavi.ai>
|
Thanks for opening this — it has been seen, and it is queued. This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence. Current review status: working through a backlog. What that means for this PR, concretely:
Things that will genuinely speed it up whenever review does happen:
If this fixes a bug, a reproduction we can run is worth more than a description of the symptom. Thanks for contributing, and sorry in advance for the wait. |
|
Thx bot -- branch updated. Will try to keep this (and the other 4) I opened today up to date with main. Take your time codeowners. |
Signed-off-by: Nelson Spence <nelson@projectnavi.ai>
|
Thanks for the sequential-result compaction fix and for recording the reparse cost alongside the memory savings. I have read the description and follow-up; this remains pending review. No routine rebase is requested just for this acknowledgement. |
Brings DeusData#2418 onto main a222715. The merge is clean. Since the branch's base 0f52d30, main added an abort path for configured test declarations (configured_failure) to cbm_pipeline_pass_definitions and a reader of cached PHP parse trees (php_import_kind_at_site in pass_pkgmap.c); the next commit adapts this change to both. The merged tree is main plus exactly this PR's two files (src/pipeline/pass_definitions.c +7, tests/test_parallel.c +60). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Two follow-ups to dropping parse trees from the sequential definitions cache, both for code main gained after this branch was cut: - php_import_kind_at_site (pass_pkgmap.c) reads a PHP call or usage site's syntax from the cached tree to tell a class site from a function or constant site. The sequential route retains no source, so without the tree every site was "unknown" and a same-named vendor `use function` or `use const` import vetoed the site's edge to the project class: `new Thing()`, `Thing $t` and `extends Thing` lost 2 CALLS and 3 USAGE edges on a three-file fixture. PHP results keep their tree; every other language still drops it. - The abort for configured test declarations (configured_failure) returned without cbm_work_arena_release, so the working arena that compaction hands back to the thread stayed held after the pass. Each new test fails without its change: ei_php_vendor_function_import_keeps_same_named_class_sites and sequential_definitions_configured_failure_releases_work_arena. The cache test now also requires PHP results to keep their tree. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
|
Thank you, @Fieldnote-Echo -- this is a valuable fix with an honest trade-off write-up. Holding the sequential cache the way the parallel extract already does (no tree, compacted), releasing the thread's working arena when the pass ends, and recording the extra cross-file LSP parse time next to the memory savings made it easy to evaluate. We pushed two commits to your branch:
What we checked on the sequential route (
Thanks again for the careful measurements -- the memory saving on small and single-worker runs is substantial. |
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
|
Thank you, @Fieldnote-Echo, for the sequential extraction memory fix and regression coverage! I merged current main into this branch to pick up the shared language-count CI correction. The prior Linux, macOS, and Windows jobs stopped at that inherited contract check before reaching the C tests. The PR-specific diff is unchanged, including the PHP parse-tree exception and arena cleanup. This refresh preserves your commits and starts a fresh set of required checks. |
|
Thank you again for the sequential memory improvement. The October updates record the PHP-tree exception, early-exit cleanup, and baseline refresh as completed on our side. No further contributor work is requested; sorry for the delay in the remaining follow-up, and I’ll follow up soon. |
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
|
Thank you, @Fieldnote-Echo, for this change and for your patience while it waited for its benchmark. Every change to indexing memory or speed gets a graph-quality bench here before it merges, and yours came out very well. We indexed six projects with a single worker (so the sequential route you changed is the one that runs; every run confirmed it), three interleaved runs per binary, current main against your change merged onto it:
The graph is byte-identical on every project and deterministic across runs, and peak memory drops by 20 to 89 percent at no time cost. Even koel, where your change deliberately keeps the PHP syntax trees, drops by two thirds because its TypeScript and JavaScript files are released. Main has moved since your last run (it also touched src/pipeline/pass_definitions.c), so we merged current main into your branch (one merge commit, e1405ea; your change is untouched) for a fresh CI run. We will merge once it is green. Please pull before pushing again. |
|
Merged as ba4122d - thank you, @Fieldnote-Echo! The sequential definitions pass now drops each file's parse tree and working arena as soon as its definitions are out, which took peak memory down by 20 to 89 percent on the six projects we benchmarked, with a byte-identical graph. Thank you for the careful change and for your patience while it waited for its bench. |
Fixes #2416
What does this PR do?
On the sequential route (50 files or fewer, or
CBM_WORKERS=1;src/pipeline/pipeline.c:2684),cbm_pipeline_pass_definitionscaches each raw result with its tree-sitter tree and uncompacted working arena until the run ends (pass_definitions.c:870-871). This change frees the tree and compacts the result before caching, as the parallel worker already does (pass_parallel.c:1233,:1290), and releases the thread's working arena when the pass ends (+7 lines of C). The graph is byte-identical on 7 sequential-route corpora (Python, Go, C/Rust). The cost is that the cross-file LSP pass re-parses these files, as it always has on the parallel route (pass_lsp_cross.c:1282)..pyfiles, 3 workers (sequential because ≤ 50 files).pyfiles,CBM_WORKERS=1sequential_definitions_cache_drops_trees_and_compactsfails on main, where a cached result still holds its parse tree.Checklist
git commit -s) — required, CI rejectsunsigned commits (DCO, see CONTRIBUTING.md)
make -f Makefile.cbm test)(run as
make -f Makefile.cbm test-par)make -f Makefile.cbm lint-ci)(for this PR's changes: CI's lint job passes on this head, and local cppcheck 2.22 / clang-format 23 add no findings over main)
Prepared with AI assistance (exploration, reproduction, verification, implementation); the spec and design decisions are mine, and I reviewed and ran everything above.