Repository navigation
bench: the datasets, rows and grammar BENCH_SPEC actually asks for - #114
Merged
Merged
Conversation
The suite measured four rows of BENCH_SPEC's eleven. The three it never ran are
not incidental: `blob 1MB` is the only workload in the spec that reaches
CORELIB_PLAN §5.1's divisible-run path, `composite` is the only one that touches
a wrapper array, non-ASCII UTF-8, depth-3 nesting, an omitted all-default field
or a two-byte field header, and `composite skip-all` is the only one that
measures the walk-and-materialize-nothing path §7.2 item 7 requires be tested.
Adds all six missing rows, driven through the API as it now is: the one-shot
`blob` row writes into a caller buffer sized by hand (the schema is unbounded,
so a generated MAX_SIZE would be the configured ceiling, not a bound), the
streaming row installs a 4096-byte buffer with a flush sink and no pass-through
permission, and the decode row is fed in 4096-byte chunks with `reset()` between
messages so the reassembly capacity is kept instead of re-acquired. The
composite decode reads into heap-free destinations, so no allocator traffic
lands in a figure that is meant to be the decoder.
What the new rows say, in Ir/op:
encode: blob 1MB one-shot 1 000 026 decode: blob 1MB 3 654 639
encode: blob 1MB streaming 13 009 127 decode: composite 22 417
encode: composite 11 514 decode: composite
skip-all 7 671
The one-shot/streaming gap is 13x — 13 instructions per payload byte against
one. `pushBytes` takes a memcpy when the run fits the buffer and a
byte-at-a-time `pushByte` loop when it does not, and a megabyte through 4096
bytes is entirely the second case. Under MB/s the same gap reads 43x
(42 064 against 970), but that row is bandwidth-bound and the Ir figure is the
one to quote.
Two supporting changes:
* The entry points are `flatten` as well as `noinline`. GCC's inlining budget is
TU-wide, so growing the file from four workloads to ten moved
`encode: typical message` from 224 Ir/op to 330 and `decode: typical message`
from 1199 to 1355 without the library changing a line. Flattened, the four
pre-existing workloads measure identically at four workloads and at ten
(226 / 1275 / 35 044 / 43 839), a couple of percent above what an
unconstrained GCC finds for a small file. A figure that is stable across
releases is worth more here than one that is minimal; the README table is
updated to the flattened readings.
* `test_bench_tools` now holds the tooling against BENCH_SPEC rather than only
against itself: the published set is the spec's, every label matches its
output grammar, both printed tables match it row for row, and the cross-port
parity sizes hold (`blob 1MB` 1 000 005, `composite` 956, `perf` 170). It
drives the real loops over a token budget through `SOFAB_BENCH_SECONDS`, which
exists for that check alone — the default stays BENCH_SPEC's ~1 s.
The Ir table's title becomes "pure-C++20" to match the label `bench` and `perf`
already print; plain "C++" is corelib-c-cpp's wrapper column.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
bench/measured four of BENCH_SPEC's eleven rows. This adds the sixthat were missing, adapts the whole suite to the API as the fix and optimisation
PRs left it, and puts the spec itself under test so a future gap fails CI
instead of showing up as a blank column in the cross-language table.
There is no issue for this one.
The gap that was there
The three absent datasets are not incidental extras:
blob 1MBis the only workload in the spec that reaches CORELIB_PLAN§5.1's divisible-run path. Every other dataset is schema-bounded and small
enough that no flush happens mid-encode, so that path had never been measured
here at all.
compositeis the only one that touches a wrapper array, non-ASCIIUTF-8, depth-3 nesting, a field the encoder is required not to write,
or a two-byte field header.
composite skip-allis the walk-the-message-materialize-nothing path that§7.2 item 7 requires be tested and that nothing so far measured.
Driven through the current API
encode: blob 1MB one-shot— caller buffer of 1,000,005 bytes, no sink. Sizedby hand, as BENCH_SPEC insists: the schema is unbounded, so a generated
MAX_SIZEwould be the configured ceiling rather than a bound.encode: blob 1MB streaming— a 4096-byte caller buffer with a flush sink,pass-through not granted (this port implements none, so BENCH_SPEC's optional
blob 1MB passthroughrow is omitted rather than stubbed). The sink consumesand discards: one XOR'd byte per call plus a byte counter, and the counter is
what the row's parity size comes from, so a row that did not move the whole
megabyte fails instead of borrowing the one-shot row's figure.
decode: blob 1MB— fed in 4096-byte chunks, so every feed but the lastreturns
INCOMPLETEand the field is reassembled across them.reset()between messages keeps the reassembly capacity, which is what the API's message
loop is for; a fresh stream per op would have put a megabyte of allocator
traffic in every iteration and measured malloc.
decode: compositereads into heap-free destinations(
InlineVector<FixedString<16>,64>,FixedString<384>) for the same reason —a
std::vector<std::string>would have charged 64 frees and 64 allocations tothe decoder.
Numbers
All measured on this branch, GCC 15,
-O3, x86-64.bash bench/run_callgrind.sh— Ir/op (deterministic)bench— MB/sperf— unchanged, and still on parityWhat the new rows say
The divisible-run path costs 13x. One-shot 1,000,026 Ir against streaming
13,009,127 — one instruction per payload byte against thirteen.
pushBytestakes a
memcpywhen the run fits the remaining buffer and falls back to abyte-at-a-time
pushByteloop when it does not, and a megabyte through a4096-byte buffer is entirely the second case. Under MB/s the same gap reads 43x
(42,064 against 970), but that row is bandwidth-bound and
Ir/opis the figureto quote. This is a measurement, not a fix — the fix belongs in a
perf:PR,and this one deliberately changes no library code.
Not-decoding is worth two-thirds of a decode.
composite skip-all7,671against
composite22,417 — the parse is the smaller half; the destinations arethe rest.
The
flattenchange, and why two README figures movedGCC's inlining budget is per translation unit, so simply growing
bench.cppfrom four workloads to ten moved
encode: typical messagefrom 224 to 330Ir/op and
decode: typical messagefrom 1199 to 1355 — in a library that hadnot changed a line. That is a benchmark that cannot be compared with its own past
readings.
The entry points are therefore
flattenas well asnoinline, which pins eachCallgrind toggle point to its own call tree. Verified: with
flatten, main'sfour workloads measure identically whether the file holds four workloads or
ten (226 / 1275 / 35,044 / 43,839). The cost is a couple of percent above the
absolute minimum an unconstrained GCC finds for a small file —
encode: typical226 vs 224,
decode: typical1275 vs 1199. A figure that is stable acrossreleases is worth more here than one that is minimal, and the README's
instruction-count table is updated to the flattened readings with that reasoning
spelled out.
Spec put under test
test_bench_toolsused to check only that the three tools agreed with eachother. It now checks that they agree with BENCH_SPEC:
output grammar;
verbatim, not a paraphrase;
blob 1MB= 1,000,005,composite= 956,perf= 170;perfis present, runs, and prints all five value lines (BENCH_SPEC: "animplementation that ships only two is incomplete").
It drives the real loops over a token budget via
SOFAB_BENCH_SECONDS, whichexists for that check alone — nothing that publishes a number changes it, and the
default stays BENCH_SPEC's ~1 s per workload. The whole test runs in 0.7 s.
The Ir table's title becomes
pure-C++20, matching the labelbenchandperfalready print; plain
C++iscorelib-c-cpp's wrapper column.Test evidence
Full
ctestgreen in all three configurations CI builds — Release, Debug, and-DSOFAB_STRICT_UTF8=0— 6/6 each.-Wall -Wextra -Wpedanticclean under GCC 15and clang 21. Confirmed failing first: on
main'sbench.cppthe new testreports the six absent BENCH_SPEC rows.