-
Notifications
You must be signed in to change notification settings - Fork 47.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fizz] Optimize end tags chunks #27522
Conversation
Comparing: 67cc9ba...d9ca72a Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
Interesting benchmark. I wonder if we should have a hardcoded switch statement for the most common tags: |
@@ -2509,7 +2509,7 @@ function pushStyleImpl( | |||
target.push(stringToChunk(escapeTextForBrowser('' + child))); | |||
} | |||
pushInnerHTML(target, innerHTML, children); | |||
target.push(endTag1, stringToChunk('style'), endTag2); | |||
target.push(endChunkForTag('style')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might as well precompute these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not well, it is already cached so the computation that causes the memory allocation is only executed once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I experimented with that method but didn't get any performance improvement. Map lookup is fast. Reducing redundant TextEncoder.encode() and String concat that causes memory allocation is very important for performance. |
I think this looks good to merge but I'll let @sebmarkbage or @gnoff decide |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it'd be impactful to just statically reference precomputed chunks for start and end tags for every function that pushes with an explicit type. So no new switch but everywhere we can avoid the map lookup we do and we only use the map for the generic path where the type is dynamic. Either way let's get this merged. LMK if you experiment with this other idea
React upstream changes: - facebook/react#27570 - facebook/react#27569 - facebook/react#27550 - facebook/react#27559 - facebook/react#27552 - facebook/react#27504 - facebook/react#27522 Co-authored-by: Josh Story <[email protected]>
Implements `endChunkForTag` to make writing end tags faster
Implements `endChunkForTag` to make writing end tags faster DiffTrain build for commit 8c85b02.
Summary
By caching '</' + tag + '>'
Chunk
, my hacker news ssr benchmarks showed an improvement of over 10% in requests/secondBenchmark: https://github.com/yujunjung/optimize-end-tag-fizz
Requests/second increased from 815 to 910
How did you test this change?