Skip to content

perf: faster merge counting — single-pass dict + inline max#25

Merged
AmitMY merged 1 commit intomainfrom
perf/faster-counting
Apr 8, 2026
Merged

perf: faster merge counting — single-pass dict + inline max#25
AmitMY merged 1 commit intomainfrom
perf/faster-counting

Conversation

@AmitMY
Copy link
Copy Markdown
Contributor

@AmitMY AmitMY commented Apr 8, 2026

Summary

  • Replace Counter with plain dict for merge counting
  • Find best merge in single pass instead of building a second Counter + most_common(1) (heap sort)
  • Remove redundant ONLY_MINIMAL_MERGES filter from trainer — Tree.get_merges() now filters at the source
  • Drop unused Counter import

Performance

Config Before After
50 samples / 200 merges 1.79s 1.72s
100 samples / 200 merges 3.03s 2.90s

~5% improvement. The remaining bottleneck is the full graph rescan each iteration — fixing that would require incremental counting (only update positions affected by a merge), which would be a larger architectural change.

Test plan

  • All 120 tests pass
  • ruff check . passes

🤖 Generated with Claude Code

@AmitMY AmitMY force-pushed the perf/faster-counting branch 2 times, most recently from c197e10 to 1b98e73 Compare April 8, 2026 18:04
- Replace Counter with plain dict for merge counting (~faster hashing)
- Find best merge in single pass instead of building a second Counter
  and calling most_common(1) (avoids heap sort)
- Remove redundant ONLY_MINIMAL_MERGES filter from trainer — Tree
  merges are now filtered at the source in Tree.get_merges()
- Drop unused Counter import

100 samples / 200 merges: 3.03s → 2.90s (~5% faster)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AmitMY AmitMY force-pushed the perf/faster-counting branch from 1b98e73 to 5781747 Compare April 8, 2026 18:11
@AmitMY AmitMY merged commit 29c072f into main Apr 8, 2026
2 checks passed
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