← Back to Pull requests

Make Declarations#to_s ~24x faster: its clean-up regexp matched at every character #193

Closed
unknown closed this pull request without merging on Oct 26, 2026 04:35 UTC
View on GitHub
unknown unknown commented on Oct 23, 2026 18:00 UTC
Author

RuleSet::Declarations#to_s cleans its output with gsub!(/^[\s^({)]+|[\n\r\f\t]|\s+$/mx, ''). [\n\r\f\t] matches the empty string, so gsub! performs a replacement at every position of the string, and since the leftmost alternative always wins, the trailing \s+$ branch can never match. That's probably what the # TODO: Clean-up regexp doesn't seem to work above it was about :)

The first commit uses /^[\s^({)]+|[\n\r\f\t]+/ instead: same output on 700,000 random strings, ~24x faster per call. Through premailer, it was 74% of all gsub! time and 11.6% of the inlining wall time on our order confirmation email.

The second commit is smaller: normalize_property skips the downcased copy when the name is already lowercase ASCII (the internal margin-top-style literals always are), and create_dimensions_shorthand! fills a plain hash instead of chaining enumerators. Happy to split it out if you'd rather review them separately.

On our 156 transactional emails, inlined with premailer, output byte for byte identical before and after:

| | CPU per email | objects per email |
|---|---|---|
| 3.3.0 | 6.9–7.2 ms | 16,059 |
| this branch | 6.1–6.2 ms | 12,603 (−21%) |

The suite passes (246 runs), RuboCop is clean.

Pre-Merge Checklist


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

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

    Diff: 175 lines (+131 / -44) across 2 files Reviewer: grosser Review duration: 3514m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.35) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.35 · 175 lines diff across 2 files
    0.35
    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.309
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #193"
    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: 35.4% (MEDIUM) · Higher = larger blast radius
    35.4%
    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: 14.0% · Safe to merge
    14.0%