Parse declarations with 2.3x fewer allocations (−32% per email through premailer) #194
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 305 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.342
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #194"
general
weight: 0.35
grosser
Following up on #193 :) Profiling premailer on our emails again, most of what css_parser still allocated came from storing and printing declarations. Every
Valuecopied its string throughsubeven with nothing to clean.reduceandeach_with_objectbuilt a[key, value]pair per declaration,casecmp?case-folded both strings, andreplace_declaration!rebuilt its hash throughzip.This branch copies a value only when it really has a trailing semicolon, an
!importantor surrounding whitespace to remove, and freezes the cleaned copy with-value, so repeated values (0,#fff,bold…) share one String. Hashes are iterated with plaineach.casecmp(IMPORTANT).zero?replacescasecmp?: I checked every codepoint, none case-folds into!important. Thestrips inCssParser.mergeare gone too, stored values are already stripped.One trade-off to flag: when the value passed in is frozen and needs no cleaning,
Value#valueis now that String or its interned twin rather than a fresh copy. Unfrozen strings are still copied, and never frozen or mutated, whether they need cleaning or not. There's a test for both cases.Against today's master, which includes #193 and #195, a parsed declaration goes from 10.4 objects to 4.4 and
declarations_to_sfrom 15 to 3. Measured end to end, median of 11 interleaved runs, Ruby 4.0.9 on an Apple M5, premailer 1.32.0, nokogiri 1.19.4:| | objects | bytes | CPU |
|---|---|---|---|
| our 167 transactional emails through premailer, per email | 13,948 → 9,448 (−32%) | 871 → 693 KiB (−20%) | ≈ |
| Mastodon's mailer CSS, parsed then merged | 42,088 → 24,586 (−42%) | 2,371 → 1,679 KiB (−29%) | −7.6% |
| premailer's own test files | 26,682 → 18,460 (−31%) | 1,733 → 1,424 KiB (−18%) | −3% |
|
rake benchmark, complex.css | 8,068 → 6,365 (−21%) | 517 → 427 KiB (−17%) | ≈ |All three corpora give byte-for-byte identical output. A differential fuzz against today's master (50,000 seeded random values, blocks, merges and shorthand round-trips, about 300,000 output lines) found no difference. The new allocation test fails on master, and is skipped on JRuby. The suite passes on Ruby 3.3 and 4.0, and RuboCop is clean.
Sister PR: #195, for shorthands and media types, now merged into this branch.
Pre-Merge Checklist
---
🤖 Generated with Claude Code, but prompted, read, and verified by @czj, a caring human :)