Skip to content

perf: linearize CollectNonLeafSubtrees, defer per-node Render#39

Merged
kyle-elliott-tob merged 1 commit into
masterfrom
perf/collect-nonleaf-linear
May 6, 2026
Merged

perf: linearize CollectNonLeafSubtrees, defer per-node Render#39
kyle-elliott-tob merged 1 commit into
masterfrom
perf/collect-nonleaf-linear

Conversation

@kyle-elliott-tob

Copy link
Copy Markdown
Collaborator

Summary

  • CollectNonLeafSubtrees called CountNodes per node — O(n²) worst case (bounded only by the 50 000-node lift gate, ~2.5e9 ops). Compute subtree size via post-order summation in a single walk.
  • Defer Render until a hash bucket actually contains another node, back-filling the existing entry on the second occurrence. Single-occurrence entries never render.
  • Closes audit finding lifting-passes-11.

Test plan

  • RepeatedSubexprLifter, ArithmeticAtomLifter, Simplifier tests (125 total) pass locally.

🤖 Generated with Claude Code

CollectNonLeafSubtrees called CountNodes per node — O(n^2) worst case
(bounded only by the 50 000-node lift gate, so ~2.5e9 ops). Compute
subtree size via post-order summation in a single walk. Defer Render
until a hash bucket actually contains another node, back-filling the
existing entry on the second occurrence. Single-occurrence entries
never render.

Closes audit finding lifting-passes-11.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kyle-elliott-tob
kyle-elliott-tob merged commit d86d44a into master May 6, 2026
9 checks passed
@kyle-elliott-tob
kyle-elliott-tob deleted the perf/collect-nonleaf-linear branch May 6, 2026 16:28
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