Skip to content

hub-client: simplify the per-keystroke attribution update#237

Merged
shikokuchuo merged 1 commit into
mainfrom
perf/attribution-skip-history-walk
May 28, 2026
Merged

hub-client: simplify the per-keystroke attribution update#237
shikokuchuo merged 1 commit into
mainfrom
perf/attribution-skip-history-walk

Conversation

@shikokuchuo
Copy link
Copy Markdown
Member

@shikokuchuo shikokuchuo commented May 28, 2026

  • The refresh path was doing redundant work on every cycle: it asked Automerge for a topologically-sorted dump of the document's full history, then cross-referenced that against the list of new changes to figure out which ones to apply.
  • Automerge's getChanges API already returns exactly that list — only the new changes, in the right order — in a single call. This PR uses it directly and drops the history scan.
  • The cost of the dropped scan scaled with the document's total edit history, so the longest-running collaboration sessions were the ones paying the most for the duplicated work.
  • New tests pin the invariant that the incremental refresh always agrees with a from-scratch rebuild — covering concurrent merges, interleaved local-and-remote edits, and the case where nothing has changed since the last cycle.

…path

updateRunListAttribution was iterating handle.history() to decide which
changes to replay, even though getChanges(workDoc, doc) already returns
exactly the new changes in causal order. The history walk added an O(N)
topoHistoryTraversal call per debounce cycle (N = total changes in the
doc) plus K decodeHeads + Map lookups, all to recompute information
getChanges already provides. processedHeads / processedHistoryIndex
remain in the state for the cold-start path's contract but are now pure
bookkeeping in the incremental path.

Adds an invariant test: incremental update must equal a from-scratch
buildRunListAttribution on the merged final doc.
@shikokuchuo shikokuchuo merged commit 9e496c5 into main May 28, 2026
4 of 5 checks passed
@shikokuchuo shikokuchuo deleted the perf/attribution-skip-history-walk branch May 28, 2026 11:47
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