← Back to Pull requests

Compute the mask penalty score in a single pass #720

Closed
unknown closed this pull request without merging on Nov 28, 2026 15:37 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 07:04 UTC
Author

Summary

ModuleMatrix.Score() read the matrix in four passes. It used about 80% of the time of GenerateQrCode.

Now Score reads each module one time. For each column, one int keeps the run length and the last 11 modules. On targets with HAS_SPAN, the scratch array comes from ArrayPool<int>.

The selected masks do not change. A differential test compared old and new code in 1.15M checks, including the renderer output. All results were the same.

Apple M2 Max (ARM64), BenchmarkDotNet. I did not measure x64.

| Benchmark (ECC L unless shown) | net8.0 | net10.0 | Allocated (net10.0) |
|---|---:|---:|---:|
| Version 1 (21×21) | −4% | −23% | no change |
| Version 1, ECC H | −16% | −22% | no change |
| Version 2 | no change | −29% | no change |
| Version 4 | −28% | −57% | no change |
| Version 10 | −40% | −45% | no change |
| Version 40 (177×177) | −40% | −44% | no change |
| Version 40, ECC H | −44% | −48% | no change |
| URL, 126 characters | −35% | −47% | no change |
| 2,600 characters | −34% | −39% | no change |

Test plan

Tests pass on net8.0 and net10.0 (673). I use macOS, so I skipped the 31 GDI+ tests. The build has no new warnings. dotnet format --verify-no-changes passes.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->

Summary by CodeRabbit

Improvements
Standard QR code generation evaluates masking patterns more efficiently while retaining the existing scoring criteria, so the resulting selection behavior remains consistent.
* On supported platforms, QR generation reuses temporary memory during standard mask evaluation, reducing allocation overhead. Micro QR code scoring continues to use its existing approach.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Diff: 226 lines (+169 / -57) across 2 files Reviewer: g4lb Review duration: 6273m
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 · 226 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.325
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #720"
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: 36.9% (MEDIUM) · Higher = larger blast radius
36.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: 14.6% · Safe to merge
14.6%