perf(fast): parallelize per-step apply, recount, and delta diff#53
Merged
Conversation
Phase profiling at the benchmark workload (2000 docs, 100 merges) showed the connected loop's cost split as apply+recount 2.8s and delta bookkeeping 0.9s, all serial. Three rayon changes, output byte-identical: - The affected-entry apply+recount loop runs via par_iter_mut (threshold 64 entries so small steps skip rayon overhead). - The old-vs-new candidate diff per entry is computed in parallel; only the few real changes are applied serially to the shared global/index (additive updates, and pick_best_entries reads index vectors order-independently). - Trainer.apply_merge parallelizes over Unconn subgraphs with memoized try_merge; SuperBPE hits this 50 times replaying phase-1 merges. Boundless 3.99s -> 1.32s (3.0x), SuperBPE 4.13s -> 0.99s (4.2x), BNE 0.50s -> 0.46s, BPE unchanged. Digests identical at 2000 and 500 samples, matching the reference on both. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
AmitMY
force-pushed
the
perf/profile-2000
branch
from
July 23, 2026 09:49
bbfbbb3 to
2495772
Compare
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.
Profiled the calibrated benchmark workload (2,000 rows / 100 merges). Phase timers showed all four cases route through
train_entries_delta, and the connected loop's cost was apply+recount 2.8s (of itseq_recount1.8s) + delta bookkeeping 0.9s — all serial. SuperBPE additionally spent 2.35s serially replaying its 50 phase-1 merges inmake_trainer.Rust-side only, per the project rule: the reference stays clean, fast/ gets the machinery. (A set of Python micro-optimizations from the same profiling round bought ~9% on connected mode but was dropped as not worth the added complexity in the reference.)
Changes (
fast/src/trainer.rs)par_iter_mut(threshold 64 entries, so small steps skip rayon overhead).global/index(updates are additive, andpick_best_entriesreads index vectors order-independently).Trainer.apply_mergeparallelizes over subgraphs with memoizedtry_merge— SuperBPE's phase-1 replay hits this 50 times.Results (benchmark defaults, before → after)
Digests unchanged and identical to the reference at 2,000 and 500 samples (
20d930a435/6598b73bb3/9999e69912). Both suites 141 passed, 2 skipped; clippy clean.Tested and rejected during profiling
Ranked next steps (measured, not done)
seq_recountfor connected mode: recount remains the largest piece of what's left; only children adjacent to a merge change.u32ids: candidate keys are deep-hashedVec<GraphV>; parallelism hid that cost rather than removing it.🤖 Generated with Claude Code