perf(parser): Phase B — TreeCursor migration for parser.Walk#146
Merged
Conversation
Replaces the recursive Node.Child(i) traversal with an iterative tree-sitter TreeCursor walk. Matches the canonical tree-sitter idiom and removes Go-level recursion frames per descent. Honest accounting: smacker's *TreeCursor.CurrentNode() still routes through Tree.cachedNode, so the per-visit *Node allocation is unchanged. The 91%-of-allocations cachedNode hot spot pprof flagged on airflow was driven by per-node *re-parse* (Task A1 fixed that by parsing once per file). Phase B's structural change keeps the public Walk(root, fn) API identical; callers and tests are untouched. Plan: docs/superpowers/plans/2026-05-13-enrich-oom-fix.md Task B1. Verification: - go test ./internal/parser/... ./internal/intelligence/extractor/... pass - go test ./... -count=1: 877 pass (unchanged from main) - Determinism preserved: pre-order DFS visitation order matches the recursive form exactly.
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
Phase B of the enrich OOM fix plan. Single task: rewrite `parser.Walk` from recursive `Node.Child(i)` to iterative TreeCursor traversal. Public API unchanged; all callers untouched.
Honest accounting
The plan estimated 90%+ allocation reduction from TreeCursor based on a generic claim that cursors avoid per-node allocation. In smacker/go-tree-sitter v0.x, `TreeCursor.CurrentNode()` still routes through `Tree.cachedNode` which heap-allocates a `*Node` on first visit per node. So Phase B does not drop allocations further from where Phase A already landed.
What this PR DOES deliver:
The 91%-of-allocations `cachedNode` hot spot pprof flagged on airflow was driven by per-node re-parse. Task A1 fixed that by parsing once per file; the additional allocation savings from Phase B alone are within noise.
Why ship it anyway
Test plan