Repository navigation
perf(preview): batch a first render and regroup only the sections an edit touched - #1025
Merged
Merged
Conversation
…edit touched A first render sanitized every block with a call of its own, and each DOMPurify call builds a document of its own: a 5MB file opened about 30% slower than with the whole-document pipeline. Blocks are now processed and sanitized in one pass, each inside a <section> carrying a nonce, and taken back out of it; markup that closes or forges one cannot know the nonce, so that batch falls back to one block at a time. Adding, removing or re-levelling a top-level heading moved every block in the document back to the top and wrapped them all again. Only the sections between the nearest heading of the edited level or higher before the edit and the next one after it are regrouped now; the folds outside keep their wrappers, and a kept heading's wrapper takes on the state the reader left it in.
PathGao
force-pushed
the
perf/preview-patch-followups
branch
from
October 24, 2026 05:36
c77ae18 to
9e7ccc8
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.
This PR builds on the previous one and fixes the two places where the block patch was still worse than it should be.
Opening a large file got slower. A first render sanitized every block with its own DOMPurify call, and each call builds its own document, so a 5 MB file opened about 30% slower than on master. A first render, and any multi-block edit, now processes and sanitizes all its blocks in one pass. Each block goes in inside a
<section>carrying a random nonce and is taken back out afterwards. Markup that closes the section early or forges one cannot know the nonce. The count or a nonce then comes out wrong, and that batch falls back to one block at a time. A test pins this with a forged marker.Adding a section regrouped the whole document. Adding, removing or re-levelling a top-level heading moved every block back to the top level and wrapped them all again. Every fold wrapper was then new, so the fold layout observer re-measured all of them. Now only the sections between the nearest heading of the edited level or higher before the edit and the next one after it are regrouped. A section of a higher level contains the change unchanged, and one of the same level ends where it did. Wrappers outside keep their identity, and a kept heading's new wrapper takes on the folded state the reader left it in.
Same harness as the previous PR, median of 2-4 runs:
##section: master / previous PR / this PRLeft out: rewriting
data-sourceposlazily, as a per-block line offset, instead of onto every node below an Enter. That would be the remaining O(document) step, about 260 ms at 5 MB. It is not small. Every reader ofdata-sourceposwould have to resolve the offset: scroll sync and anchor restore inpreviewAnchor.ts, the line mapping inlineCoordinates.ts, and the task checkbox toggle. So it is not in this stack.Risks: same as the previous PR. Not yet verified in the real Tauri app.
Tests: the parity spec gains a new subsection, a new top-level heading and a heading that changed level.
previewPatch.spec.tsgains these cases:npm run check,npm test, vitest (583), andcargo fmt/clippy/testpass.