Repository navigation
Skip notifications while innerHTML builds its fragment - #160
Open
natemoo-re wants to merge 1 commit into
Open
natemoo-re wants to merge 1 commit into
natemoo-re wants to merge 1 commit into
Conversation
commit: |
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 does this PR do?
Stacked on #159.
Stops the
innerHTMLsetter from sending change notifications while it builds the parsed fragment. Before this change, every node the sink inserted, and every attribute it set, notified the document, soRenderApi.requestadded the node and its detached ancestors to the next frame's change set. Parsed nodes never need those marks.Layoutreuses an element's previous output, or its cached style, only after that element has been laid out (opened) in an earlier frame. A node the parser just created hasn't been, so marking it changed does nothing.The marks the replay does need come from the swap into the target element: removing the old children and inserting the new top-level nodes marks the element, its ancestors and the new children. The swap still notifies as before.
Documentgets abuildDetached(document, build)hook, using the samestatic {}pattern ascreateParsedElement. Whilebuildruns, the document drops notifications. It restores the previous state infinally, so a parse error or a nested call can't leave notifications off.parseFragmentbuilds its fragment inside the hook. The setter swaps the result in outside it.Numbers
These are the median CPU µs to set
innerHTMLon a connected element, with the realRenderApiasnotify. Each figure is the median of 400 sets. The table shows the first of three interleaved before/after runs (load avg ~9–11):Across the three pairs, the geomean went from 95–101 µs to 69–72 µs, about 26–30% lower. With a no-op
notify, the same benchmark measures about 62 µs, so what's left above that is the swap's own notifications, which the replay needs.Tests
layout.test.ts: drives the realRenderApi. After twoinnerHTMLreplacements, including nested parsed elements that aren't in the change set, each frame's output matches a full layout, and the untouched sibling is still replayed. Suppressing the swap's notifications makes this test fail.parse.test.ts: the swap notifies the host and its new top-level child, and nested parsed nodes are never notified.Type of change
Checklist
pnpm test)pnpm format)AI-generated code disclosure