pp_reverse - chunk-at-a-time string reversal #23371
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 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.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #23371"
general
weight: 0.35
bulk88
The performance characteristics of string reversal in blead is very variable depending upon the capabilities of the C compiler. Some compilers are able to vectorize some cases for better performance.
This commit introduces explicit reversal and swapping of whole registers at a time, which all builds seem to be able to benefit from.
The
_swab_xx_macros for doing this already exist in _perl.h_, using them for this purpose was inspired byhttps://dev.to/wunk/fast-array-reversal-with-simd-j3p The bit shifting done by these macros should be portable and reasonably performant if not optimised further, but it is likely that they will be optimised to _bswap_, _rev_, _movbe_ instructions.
Some performance comparisons:
1. Large string reversal, with different source & destination buffers
my $x = "X"x(1024100010); my $y; for (0..1_000) { $y = reverse $x }gcc blead:
clang blead:
gcc patched:
clang patched:
2. Large string reversal, but reversing the buffer in-place
my $x = "X"x(1024100010); my $y; for (0..1_000) { $y = reverse "foo",$x }gcc blead:
clang blead:
gcc patched:
clang patched:
3. Short string reversal, different source & destination (checking performance on smaller string reversals - note: this one's vary variable due to noise)
my $x = "1234567"; my $y; for (0..10_000_000) { $y = reverse $x }gcc blead:
clang blead:
gcc patched:
clang patched:
---------------------------------------------------------------------------------