← Back to Pull requests

Use chunked fills to optimize buffered padding #4959

Closed
unknown closed this pull request without merging on Oct 02, 2026 18:44 UTC
View on GitHub
unknown unknown commented on Sep 28, 2026 03:37 UTC
Author

Fill appender padding in chunks

Padding through basic_appender currently writes one buffer element at a time. This adds a fill_n overload that fills contiguous buffer space, continuing after growth or flushing.

Also adds tests for large counting/truncated output and non-ASCII wide fills.

All speedups are C++20 and later only, because we have to fall back to the old slow path when we don't have std::is_constant_evaluated.

Benchmarks

4 cases, timed separately. The first three cycle through 256 runtime-generated unsigned values below 100,000,000. Comments show untimed setup; value shows one example input.

// const unsigned value = 85662526;

// ***Buffer***
// fmt::memory_buffer buf;
// buf.reserve(8192);
buf.clear();
fmt::format_to(fmt::appender(buf), FMT_COMPILE("{:*>1024}"), value);

// ***Size***
auto size = fmt::formatted_size(FMT_COMPILE("{:*>1024}"), value);

// ***Truncate***
// std::array<char, 8192> raw;
auto result =
    fmt::format_to_n(raw.data(), 16, fmt::runtime("{:*>1024}"), value);

// ***listing***
// const std::array<std::pair<std::string_view, std::uintmax_t>, 3> files{{
//     {"index.html", 4821}, {"app.js", 128734}, {"README.md", 2031}
// }};
fmt::memory_buffer out;
out.reserve(files.size() * 64);
for (const auto& [name, bytes] : files)
  fmt::format_to(fmt::appender(out), "{:<40} {:>12}\n", name, bytes);
auto output = fmt::to_string(out);

The first 3 cases are microbenchmarks; the 4th case is intended to mimic a more realistic/common usecase.

Performance

Compiled with -std=c++20 -O3 -DNDEBUG. Library and consumer compiled separately (without lto).

Elapsed-time reductions, using 4 compilers and 3 different computers:

| CPU | Compiler | Buffer | Size | Truncate | Listing |
|---|---|---:|---:|---:|---:|
| Ryzen 9 9950X | GCC 11.5.0 | 96.28% | 94.52% | 89.82% | 14.41% |
| Ryzen 9 9950X | GCC 16 snapshot | 96.99% | 95.33% | 92.68% | 14.87% |
| Ryzen 9 9950X | Clang 17.0.6 | 95.87% | 93.79% | 89.33% | 8.28% |
| Ryzen 9 9950X | Clang 22.1.2 | 96.25% | 94.25% | 90.19% | 13.26% |
| Core i5-1230U | GCC 11.5.0 | 96.66% | 93.83% | 89.34% | 17.37% |
| Core i5-1230U | GCC 16 snapshot | 95.55% | 92.91% | 88.41% | 20.10% |
| Core i5-1230U | Clang 17.0.6 | 96.77% | 94.15% | 90.05% | 11.87% |
| Core i5-1230U | Clang 22.1.2 | 96.78% | 93.88% | 90.24% | 18.02% |
| Core i5-6600 | GCC 11.5.0 | 97.84% | 96.43% | 93.68% | 20.62% |
| Core i5-6600 | GCC 16 snapshot | 97.23% | 96.05% | 93.51% | 21.66% |
| Core i5-6600 | Clang 17.0.6 | 97.92% | 96.95% | 94.35% | 19.70% |
| Core i5-6600 | Clang 22.1.2 | 97.86% | 96.91% | 94.42% | 18.30% |

So ~10-40x faster on microbenchmarks, and ~8-20% less elapsed time on the 4th benchmark.

GCC 16 is the 20260322 snapshot; Clang 17 uses GCC 14 headers.

Each comparison uses 24 randomized, balanced process pairs, with CPU pinning and warmups. All 48 per-comparison 99% confidence intervals exclude zero.

The format.cc code-size increases were 48–135 bytes, at most ~0.12%.

A broader set of benchmarks found no regressions in performance anywhere (except for in cases where code layout had significant performance implications).

Diff: 403 lines (+302 / -101) across 5 files Reviewer: Boulea7 Review duration: 6666m
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.45) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 403 lines diff across 5 files
0.45
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%
56%
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.359
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #4959"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% 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: 44.8% (MEDIUM) · Higher = larger blast radius
44.8%
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: 56.8% · Lower = rushed or shallow review
56.8%
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: 19.4% · Safe to merge
19.4%
Repository