← Back to Pull requests

Skip the colour regexp on comma-free shorthands, return sanitized media types as-is: −7% objects, −4% CPU #195

Closed
unknown closed this pull request without merging on Oct 27, 2026 02:58 UTC
View on GitHub
unknown unknown commented on Oct 26, 2026 07:14 UTC
Author

The smaller sister of #194, two independent bits that are each too small for a PR of their own.

Shorthands first. expand_dimensions_shorthand! ran RE_COLOUR, the alternation of every named colour, over each margin, padding and border value, only to collapse the spaces around commas inside rgb()/hsl(). Without a comma that replacement is the identity, so it's now skipped when the value has no ,, along with the dup it no longer needs. create_dimensions_shorthand!, compute_dimensions_shorthand and create_shorthand_properties! also stop building throwaway arrays, enumerators and zip pairs: 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 meant to_s, gsub, strip! and to_sym just to get the same symbol back. Such a symbol is now returned as-is. UNSANITIZED_MEDIA_QUERY_RX lists exactly what the slow path would change: blank, padded, or not separated by single spaces. Two crumbs ride along: calculate_specificity counts ids with count('#'), and parse_selectors! maps in place.

Median of 8 interleaved runs, Ruby 4.0.9, premailer 1.30.0, nokogiri 1.19.4:

| | objects | CPU |
|---|---|---|
| our 336 transactional emails through premailer | 13,592 → 12,666 (−7%) | −4% |
| Mastodon's mailer CSS, parsed then merged | 40,702 → 37,496 (−8%) | −5% |
| premailer's own test files | 28,502 → 26,590 (−7%) | −5% |
| rake benchmark, complex.css | 8,459 → 7,941 (−6%) | ≈ |

All three corpora give byte-for-byte identical output. The 360,000-input differential fuzz against master covers shorthands, sanitize_media_query on 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 :all takes 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


  • CHANGELOG.md updated with short summary
  • ---

    🤖 Generated with Claude Code, but prompted, read, and verified by @czj, a caring human :)

    Diff: 292 lines (+219 / -73) across 3 files Reviewer: grosser Review duration: 1183m
    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 · 292 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.340
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #195"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.9% (MEDIUM) · Higher = larger blast radius
    39.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.8% · Safe to merge
    15.8%