← Back to Pull requests

Stop sub after the first match and reuse plain replacements #315

Closed
unknown closed this pull request without merging on Nov 29, 2026 01:59 UTC
View on GitHub
unknown unknown commented on Nov 25, 2026 14:29 UTC
Author

sub() found every match but replaced only the first. Now it finds only the first match. A replacement without & or \ is also reused for each match. A call with no match does not read the replacement. The output does not change.

| Case | Time | Bytes | Allocs |
|---|---|---|---|
| BuiltinSub | 8.12 → 3.10 µs | 7548 → 2606 B | 106 → 30 |
| BuiltinSubAmpersand | 8.24 → 2.99 µs | 7548 → 2607 B | 106 → 30 |
| BuiltinGsub | 9.61 → 8.87 µs | 12125 → 11876 B | 147 → 102 |
| BuiltinGsubAmpersand | 9.60 → 9.51 µs | 12137 → 12122 B | 147 → 147 |
| BuiltinSubstr | 482 → 402 ns | 0 → 0 B | 0 → 0 |
| sub, first of many, long line | 49.6 → 33.5 µs | 119.3 → 111.1 KB | 68 → 58 |
| sub with &, first of many | 48.1 → 32.8 µs | 119.3 → 111.1 KB | 69 → 58 |
| sub, no match | 33.8 → 33.3 µs | 113.9 → 109.4 KB | 64 → 61 |
| gsub, plain | 48.6 → 48.3 µs | 119.3 → 119.3 KB | 68 → 68 |
| gsub with & | 51.6 → 51.8 µs | 120.3 → 120.3 KB | 268 → 268 |
| gsub, short line | 32.8 → 32.8 µs | 108.9 → 108.9 KB | 59 → 59 |
| sub, no match, 4 KB replacement | 248 → 190 µs | 173.8 → 126.9 KB | 4064 → 1064 |
| gsub, no match, 4 KB replacement | 246 → 241 µs | 173.7 → 173.7 KB | 4064 → 4064 |
| sub, no match, short replacement | 239 → 182 µs | 169.7 → 122.8 KB | 4060 → 1060 |
| sub, 4 KB replacement | 8.06 → 1.96 ms | 25.2 → 4.8 MB | 14087 → 3071 |
| gsub, short replacement | 407 → 383 µs | 176.9 → 176.9 KB | 5055 → 5055 |
| gsub, 4 KB replacement | 16.27 → 16.25 ms | 55.1 → 55.1 MB | 24110 → 24110 |
| gsub with &, many matches | 1.43 → 1.42 ms | 348.8 → 348.8 KB | 21050 → 21050 |

No row was slower in all 3 code layouts (AMD EPYC 9V74, Go 1.27.4, 24 rounds). BuiltinSubstr does not call the changed code. Its time moved by −17% to +17% with the code layout. go test -race passes with a master build as -awk. Old and new output matched on 1M random inputs.

Diff: 237 lines (+177 / -60) across 2 files Reviewer: g4lb Review duration: 5009m
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 237 lines diff across 2 files
0.37
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.327
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #315"
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: 37.2% (MEDIUM) · Higher = larger blast radius
37.2%
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.7% · Safe to merge
14.7%
Repository