Repository navigation
Skip the colour regexp on comma-free shorthands, return sanitized media types as-is: −7% objects, −4% CPU - #195
Merged
grosser merged 2 commits intoOct 27, 2026
Conversation
…ithout commas
expand_dimensions_shorthand! ran RE_COLOUR, the alternation of every named
colour, over each dimension value only to collapse spaces around commas in
rgb()/hsl(): without a comma that is the identity. Creating dimension and
list/background shorthands stops building throwaway arrays and zip pairs.
sanitize_media_query returns an already sanitized symbol as-is instead of
round-tripping :all through to_s/gsub/strip!/to_sym for every rule;
calculate_specificity counts ids with count('#') and RuleSet#initialize no
longer builds a selectors array only to replace it.
Inlining our 336 emails with premailer allocates 7% fewer objects and uses
4% less CPU, with byte-for-byte identical output.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 26, 2026
Parsing selectors before specificity, offset and filename were set changed what a subclass overriding parse_selectors! could see, and which error bad arguments raised, for a single saved array. GC.stat counts allocations of every thread, so the helper keeps the minimum of three runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
grosser
reviewed
Oct 27, 2026
Comment on lines
-649
to
+641
| return [:top] if values.values.uniq.count == 1 | ||
| return [:top] if values[:top] == values[:right] && values[:right] == values[:bottom] && values[:bottom] == values[:left] |
Contributor
There was a problem hiding this comment.
kinda sad ... maybe a comment about not using values.uniq.count because that is slower to make sure nobody reverts this
grosser
reviewed
Oct 27, 2026
| assert_equal "@media aural and (device-aspect-ratio: 16/9) {\n body {\n color: black;\n }\n}\n", @cp.to_s | ||
| end | ||
|
|
||
| def test_sanitizing_an_already_sanitized_media_type_does_not_allocate |
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.
The smaller sister of #194, two independent bits that are each too small for a PR of their own.
Shorthands first.
expand_dimensions_shorthand!ranRE_COLOUR, the alternation of every named colour, over each margin, padding and border value, only to collapse the spaces around commas insidergb()/hsl(). Without a comma that replacement is the identity, so it's now skipped when the value has no,, along with thedupit no longer needs.create_dimensions_shorthand!,compute_dimensions_shorthandandcreate_shorthand_properties!also stop building throwaway arrays, enumerators andzippairs: they read the four sides directly and compare them with==.Then media types.
add_rule_set!sanitizes the media types of every rule. For:all, or any symbol already in sanitized form, that meantto_s,gsub,strip!andto_symjust to get the same symbol back. Such a symbol is now returned as-is.UNSANITIZED_MEDIA_QUERY_RXlists exactly what the slow path would change: blank, padded, or not separated by single spaces. Two crumbs ride along:calculate_specificitycounts ids withcount('#'), andparse_selectors!maps in place.Median of 8 interleaved runs, Ruby 4.0.9, premailer 1.30.0, nokogiri 1.19.4:
rake benchmark, complex.cssAll three corpora give byte-for-byte identical output. The 360,000-input differential fuzz against master covers shorthands,
sanitize_media_queryon strings and symbols, specificity and selector parsing, with no difference found. Both new tests fail on master: creating margin and padding shorthands takes 39 objects there and 25 here, sanitizing:alltakes 3 there and 0 here. The suite passes on Ruby 3.3 and 4.0, and RuboCop is clean.Two heads-ups. Only CHANGELOG.md conflicts with #194, and I'll rebase whichever lands last. #184 also touches
parse_selectors!, which makes one trivial line to resolve.Pre-Merge Checklist
🤖 Generated with Claude Code, but prompted, read, and verified by @czj, a caring human :)