Make Declarations#to_s ~24x faster: its clean-up regexp matched at every character #193
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
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.309
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #193"
general
weight: 0.35
grosser
RuleSet::Declarations#to_scleans its output withgsub!(/^[\s^({)]+|[\n\r\f\t]|\s+$/mx, '').[\n\r\f\t]matches the empty string, sogsub!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 workabove 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 allgsub!time and 11.6% of the inlining wall time on our order confirmation email.The second commit is smaller:
normalize_propertyskips the downcased copy when the name is already lowercase ASCII (the internalmargin-top-style literals always are), andcreate_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
---
🤖 Generated with Claude Code, but prompted, read, and verified by @czj, a caring human :)