Repository navigation
⚡️ perf(css): merge rules across bang comments - #2535
Merged
Merged
Conversation
A /*! ... */ comment between two rules kept them apart, so a stylesheet that separates identical rules with license comments never merged them. A comment takes no part in the cascade: the rules now merge as if it were absent, and the comment is written after the merged rule, still once and verbatim. A rule run that spans comments still folds in one pass, so the merge stays linear.
Merging this PR will not alter performance
Comparing Footnotes
|
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.
A
/*! ... */comment between two rules kept them from merging, so on the minify-css-merges row "200 rules with comment barriers" (.aN{color:red}joined by/*!keep*/) turbohtml wrote the input back unchanged. A comment takes no part in the cascade, so rules now merge as if it were absent. The comment is still written once and verbatim, after the merged rule:a{color:red}/*!k*/b{color:red}→a,b{color:red}/*!k*/. A run of same-body rules that spans comments still folds in one pass. Without that, each rule rebuilt the whole selector list and the row cost 4.4x more instructions.The remaining gap is the 199 copies of
/*!keep*/(1791 bytes). lightningcss drops bang comments, and esbuild keeps one copy of each distinct legal comment. Both lose license text that turbohtml documents it keeps, so neither transform is done here. No other minify-css, minify-css-merges or minify-css-conflicts case changes size, animate.css, pico and bootstrap included.Callgrind, release+LTO, Ir per call counted inside the extension, (n=50 − n=10)/40: the worst row is +0.42% (
minify-css"320 rules, unitless exponent"), and the barrier row is −7.7%. Whole-process Ir moved by ±20% between runs of the same build. That came from glibcrealloccopying or growing in place depending on heap layout, so it was excluded.