Repository navigation
perf(composer): reuse per-keystroke projections, snapshots and reference scans - #2590
Draft
kalvinnchau wants to merge 1 commit into
Draft
kalvinnchau wants to merge 1 commit into
kalvinnchau wants to merge 1 commit into
Conversation
…nce scans memoize projectComposerDocument on the immutable prosemirror doc and readComposerSnapshot on the snapshot object, so the filter, normalizer, render and decoration passes of one key share a single projection and schema parse. the editable input drops its own per-view projection cache, now redundant. cache messageReferences in decorationsFor on text plus profiles/named/agents identity, build the emoji shortcode set once per renderable catalog, and skip the shortcode set in renderedEmoji when the draft has no colon. adds a regression test that a channel arriving or leaving invalidates the reference cache. Signed-off-by: Kalvin C <kalvin@squareup.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
Each keystroke in the rich composer runs several passes over the draft: the input filter, the normalizer, the render, the decorations and the selection handlers. Each pass projected the ProseMirror document into a draft again, and each read of the saved snapshot ran a schema parse again. Decorations also re-scanned the whole draft for
#channeland agent references on every pass, the emoji shortcode set was rebuilt on every render, and emoji sizing built that set even for drafts without a:. The work grows with the draft and runs several times per key.Change
projectComposerDocumentis memoized per document (aWeakMapon the immutable ProseMirror doc), andreadComposerSnapshotper snapshot object. The passes of one key share a single projection and parse.EditableInputdrops its own per-view projection cache, which this replaces.decorationsForkeeps the lastmessageReferencesresult and reuses it while the text, profiles, channels and agents are the same objects.useMemo), and emoji sizing returns early when the draft has no:.No behavior changes
The projection reads only the document and the fixed schema, and the snapshot parse reads only the snapshot, so both caches return what a fresh call would. The reference cache is keyed on every input the scan reads, so a channel that is added, renamed or archived misses the cache. A new test checks that a channel arriving or leaving updates the reference decoration. Sizing a draft without a
:was already a no-op, because only:shortcode:is replaced.Evidence
Bench: type one character at the end of a draft in a mounted
RichComposerInput(jsdom), with 2,000 channels and 1,000 custom emoji. Drafts are prose with links, of 200, 3,000 and 10,000 characters; the last row adds a#channeland a:shortcode:every 30 words. Medians per key, stock and this PR interleaved on a Linux and a macOS workstation.Lower is better. There are 8 samples per cell. These are jsdom timings without CPU throttling, so they exclude layout and paint; long plain drafts are dominated by work this PR does not touch.
Checks: the composer unit suites pass (
EditableInput,RichComposerInput,composer-document,emoji-size,mention-draft), along withtscandbiome.🤖 Generated with Claude Code