Repository navigation
perf: walker based transformHtmlTemplate - #581
Merged
Merged
Conversation
- Created comprehensive benchmark testing different HTML complexity levels - Tests basic, complex, multiple head pushes, and large template scenarios - Initial results show 13.77x performance difference between basic and large templates 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Updated benchmark-results.md with comprehensive performance comparison - Added all packages/unhead/src changes that improve performance significantly - Large HTML template processing improved by 5.94x (5,936 → 35,260 ops/sec) - Performance gap between basic and large templates reduced from 13.77x to 2.44x - Includes benchmark test suite for ongoing performance monitoring 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Contributor
Bundle Size Analysis
|
transformHtmlTemplatetransformHtmlTemplate
harlan-zw
marked this pull request as ready for review
September 18, 2025 04:46
Closed
1 of 6 tasks
Closed
1 of 6 tasks
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.
🔗 Linked issue
#572, #578
❓ Type of change
📚 Description
Users are advised to use the
transformHtmlTemplate()when modifying the HTML to add the Unhead tags. This function accounts for the HTML containing tags that may duplicate or cause inefficient loading by stripping tags, adding them into Unhead and then re-rendering them out.This function was powered by regex and is performing very slow (#572) for large HTML files. This is due to the regex itself requiring several passes of the entire underlying HTML.
We can solve this using a custom HTML parser but they're mostly overkill for what we need to do, which is just extract text from the
<head>. I had experience working on a custom HTML parser for https://github.com/harlan-zw/mdream, which is fairly well tested, so we copy the relevant implementation. In this PR we migratetransformHtmlTemplate()to use this new parser.We also expose a function
transformHtmlTemplateRaw()which assumes the HTML template does NOT contain any head data that may duplicate or cause order issues. This avoids any sort of HTML parsing and just does simple insertions of the unhead tags at the relevant positions.Benchmarks
Basic HTML Template: +21% (85K → 103K hz)
Complex HTML Template: +1,120% (352 → 4,296 hz)
Multiple Head Pushes: +19% (53K → 63K hz)
Large HTML Template: +47% (35K → 51K hz)
New
Previous