Skip to content

perf(engine): implement matsumoto line group partitioning - #46

Merged
HarshK97 merged 4 commits into
mainfrom
feature/line-partition
Aug 3, 2026
Merged

perf(engine): implement matsumoto line group partitioning#46
HarshK97 merged 4 commits into
mainfrom
feature/line-partition

Conversation

@HarshK97

@HarshK97 HarshK97 commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Problem

  1. AST matching algorithms like TopDown and MatchUnmatchedLeaves compare nodes across the entire AST without line boundary constraints. On large files (1,000+ lines), this causes candidate combinatorial explosion where thousands of untouched subtrees are repeatedly compared against edited regions. So it takes over 200ms and 190MB of heap allocations per diff.
  2. Unconstrained tree matching occasionally cross-matches identical syntax tokens (such as public void or return statements) in untouched lines against inserted or deleted code blocks elsewhere in the file.

What Changed

  • Line Partitioning: Added LinePartition in internal/engine/partition.go, implementing the two-group line partitioning strategy from Matsumoto et al. ("Beyond GumTree"). It classifies lines into Group 1 (non-edited lines) and Group 2 (edited lines) using line-level LCS.
  • Matcher Integration: Enforced CanMatch checks in TopDown and MatchUnmatchedLeaves so untouched subtrees only match corresponding untouched lines, while edited subtrees only match other edited regions. Cross-matching between untouched and edited lines is blocked.
  • Unit Tests: Added unit tests in internal/engine/partition_test.go covering line classification, mapped line offset checks, and group boundary isolation.

Benchmark Results

  • Large Diff Latency (Geometric Mean): Dropped from 115.30ms to 66.68ms (42.17% overall speedup, 1.73x faster)
  • Large Diff Memory (Geometric Mean): Dropped from 113.10MB to 64.43MB (43.04% overall memory reduction, ~48.7MB saved per diff)

@HarshK97
HarshK97 force-pushed the feature/line-partition branch from dda2ff0 to 39e38a3 Compare August 3, 2026 08:27
Base automatically changed from feature/line-diff to main August 3, 2026 08:37
@HarshK97
HarshK97 merged commit 064a324 into main Aug 3, 2026
8 of 12 checks passed
@HarshK97
HarshK97 deleted the feature/line-partition branch August 3, 2026 08:39
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