perf(attribution): speed up the Authors overlay producer (~30× at 10k changes)#225
Merged
Conversation
Rebuilt on every debounced payload update; switching the storage from boxed `Array<number>` to a contiguous `Uint32Array` is 5-30% faster beyond ~10KB documents (V8 microbench across ASCII/mixed/CJK) and halves the per-codeunit heap footprint. Smaller docs unchanged.
Move the chunk yield from the top of the loop to between chunks, guarded by `chunkEnd < history.length`. A history that fits in one chunk now never pays an idle-callback round-trip; longer builds save one yield as well. Runs output unchanged; existing tests pass.
buildRunListAttribution pre-indexes changes by hash and forward-replays via `A.applyChanges` with patchCallback. Eliminates the super-linear `A.diff` cost: ~30x faster at N=10000 changes (4.1s → 142ms in Node bench). Runs verified equivalent across append-only, mixed-edit, and multi-actor (sequential + diamond-DAG) fixtures. The RunListAttribution state carries an internal `_workDoc` so incremental updates apply only new changes; hand-built states without it fall back to HistoryCompactedError → full rebuild.
Member
|
Excellent!! |
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.
What
Four commits, each landing a discrete win on the JS-side attribution producer (
buildRunListAttribution/useAttribution, the code that builds the payload behind the Authors overlay).Replay history via
A.applyChangesinstead of per-stepA.diff(7a6bc8a4). The old loop calledA.diff(doc, prevHeads, currHeads)per history step, which scales super-linearly with doc state. The new loop pre-indexes changes by hash and forward-replays throughapplyChanges+patchCallback, which is O(1) per change.Runs verified equivalent across append-only, mixed-edit, and multi-actor (sequential + diamond-DAG) fixtures.
Drop one yield per build (
abee1827). Moved the chunk-yield from the top of the loop to between chunks; a history that fits in one chunk (≤CHUNK_SIZE) now never pays an idle-callback round-trip and short builds finish synchronously.Uint32Arrayfor the char→byte map (a35e33e0). Rebuilt on every debounced payload; switching from boxedArray<number>to a single contiguousUint32Arraycuts allocations and halves the per-codeunit heap footprint. 5–30 % faster from ~10 KB documents up; smaller docs are at-worst-noise.CHUNK_SIZEdoc comment (a5081334) — refreshed to reflect the new applyChanges cost profile (≈15 µs/entry, roughly constant in N) instead of the obsoleteA.diffnumbers.Why
Cold-start of the Authors overlay on long histories was the dominant wallclock, driven by
A.diffreloading historical doc state on every step. The rewrite makes it linear; the smaller wins remove the leftover papercuts so the producer is fast even on a 30 k-change document (375 ms vs the old 36 s).