Skip to content

perf(actions): use cnode and O(1) parent checks in chawathe edit script generator - #66

Merged
HarshK97 merged 1 commit into
mainfrom
feat/cnode-optimization
Aug 8, 2026
Merged

perf(actions): use cnode and O(1) parent checks in chawathe edit script generator#66
HarshK97 merged 1 commit into
mainfrom
feat/cnode-optimization

Conversation

@HarshK97

@HarshK97 HarshK97 commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Problem

  1. GenerateEditScript was cloning full 12-field ASTNode trees during edit script generation, so it was creating heavy memory allocations and constant double-map lookups between copies and originals.
  2. Sibling alignment was running linear slices.Contains(x.Children, dst) checks on every candidate pair, so alignment turned into an $O(K^2)$ scan whenever nodes had large child lists.
  3. LCS dynamic programming was allocating 2D slices on every single call, adding constant memory churn during tree traversal.

What Changed

  • Replaced full ASTNode tree copies with a small 5-field cnode struct (orig, nodeType, label, parent, children) that holds only what Chawathe needs.
  • Switched child alignment parent checks to direct pointer comparisons (dst.Parent == x and src.parent == w), so parent verification drops from $O(K^2)$ to $O(1)$.
  • Flattened the 2D DP matrix in lcs() into a single 1D slice buffer, adding fast-paths for $m=1, n=1$ sequences.
  • Updated unit tests in internal/actions/action_test.go to test cnode tree copying and child insertion directly.

@HarshK97
HarshK97 merged commit 15a2eff into main Aug 8, 2026
13 checks passed
@HarshK97
HarshK97 deleted the feat/cnode-optimization branch August 8, 2026 08:42
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