Repository navigation
perf(ui): build DOM nodes 3–4x faster - #149
Merged
Merged
Conversation
commit: |
Merging this PR will not alter performance
Comparing Footnotes
|
cowboyd
reviewed
Dec 2, 2026
cowboyd
left a comment
Contributor
There was a problem hiding this comment.
It makes me giddy to think how performant this is going to be
dreyfus92
approved these changes
Dec 2, 2026
dreyfus92
left a comment
Member
There was a problem hiding this comment.
nice, the per commit numbers make this really easy to follow. overall looks good to me
natemoo-re
force-pushed
the
natemoo-re/ui-node-weight-a54c4d
branch
from
December 3, 2026 03:26
c602acb to
fe7d37e
Compare
3 tasks done
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 improves the performance of Node creation after profiling. Eagerly creating Node properties before anything reads them was causing a lot of overhead. We now generate attribute properties the first time
attributesis read, among some other laziness tweaks. (LazyEventTargetsetup was dropped from this PR, since #111 replaced that path with its own listener registry.)No conflicts with #143 ❤️
Slop Output
This PR makes building DOM nodes with
createElement,setAttribute, andappendChild3–4x faster. Observable DOM behavior is unchanged.A CPU profile of building small trees on
mainshowed most of the time going to bookkeeping that nothing reads:NamedNodeMap#changed(13.5%) rebuilt every indexed and named property on each attribute change, even when nothing had readelement.attributes.asciiLowercaseandasciiUppercase(about 20%) ran a regex replace on every tag and attribute name.Each commit fixes one of these and was measured on its own. The figures below compare each commit with the one before it, so the commits can be reviewed one at a time. They were measured before the rebase onto #111 and #150:
Overall
Median µs per tree, from an in-process harness that alternates
main(966ab37, after #111 and #150) and this branch. It was run twice, with the same ratios each time.Behavior
NamedNodeMapcreates its indexed and named properties the first timeelement.attributesis read, then keeps them live. Script can only see these properties throughattributes, so nothing observable changes.Node.prototype, as in browsers.Object.keys(node)no longer lists them.Tried and dropped
These were measured and either didn't help or were too small to justify the change:
NamedNodeMaplazilychildNodeslazily. This was slower, and layout reads every node's children anyway.nodeNamecacheStyleDeclaration's!importantset lazilycreateElementcalls