Repository navigation
fix: highlight code beyond the first screen after a document opens - #697
Merged
Merged
Conversation
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.
Summary
Opening a document highlighted every code block before the editor could respond, in one main-thread task, so a document made mostly of code missed #638's 3 s open budget from about 200 KB. Shiki's JavaScript regular-expression engine takes about half a millisecond per line of code, and highlighting was 81–82% of opening code documents in #680.
MapResult.deletedbecause ProseMirror also reportsdeletedAfterfor a plain insertion at the position, which would drop a block whenever something was inserted right before it.requestIdleCallback: in the release WebView2 window on Windows 11, idle callbacks stopped firing altogether after a document opened, onmainas well, while animation frames and timers ran.docs/specification.mdnow states a supported size of 200 KB, the largest size at which every shape Measure large documents again after the #638 fixes and set a supported size #680 measured meets both budgets: at 500 KB, tables miss the open budget and typing in a code block misses the keystroke budget. The specification also says a code-heavy document is shown before all of its code is highlighted,docs/architecture.mddescribes the mechanism, andCHANGELOG.mdrecords the faster opening.Related Issue
Closes #683
Verification
pnpm check:frontendpassed.Manually verified in release builds on Windows 11,
mainand this branch both built from 9aa80f9 under a separate application identity with #680's method and fixtures, opening each fixture in a fresh process and typing 5 keystrokes per target:Opening code documents. "Shown" is when the document appears and the window responds; on
mainthat is also when all of its code is highlighted.main: shownKeystrokes after highlighting finished took as long on both builds: a median paint of 32–48 ms in a paragraph and 80–88 ms in a code block at 200 KB, and 136–224 ms in a code block at 500 KB.
Not verified: the release timings on top of #693, which
maingained after they were taken; scrolling during the background pass; and how the pass behaves in a window behind others or minimized.Notes
main's single freeze did, because every slice's transaction redraws the editor; a CPU profile puts about a quarter of the pass there, mostly in ProseMirror'sDecorationSet.forChildwalking the decoration set once per top-level node, which every keystroke pays as well.