report design
Design goal
A benchmark report must be reproducible from the audit record and safe to
share, and its conclusions must follow from rules the run declared. report
is a pure projection from the JSONL event stream to Plot IR (ir_model) and
from Plot IR to JSON, SVG, HTML and text. It shows the confirmatory timings of
every implementation at every scale, compares each implementation with a
baseline under the threshold and outlier policy recorded in the run, and never
lets an invalid measurement look like a valid one.
Constraints
- The same JSONL must give the same bytes on every target, so the functions are pure and do no IO.
- The HTML must render without network access, years later.
- Strings in events come from payloads and may contain markup.
- Records come from different versions:
phase,scale,block_id,protocolandseedmay be missing, and a reader must still produce an honest report. - A decision needs paired blocks, a threshold, an outlier policy and a seeded interval; it must be recomputable from the record alone.
Mathematical background
The projection
Let the stream be a sequence of events. Write for the observations with
valid true, batch_sink "kept", and phase "confirmatory" or absent;
for the observations with valid true and batch_sink "kept" but
another phase; and for the set of keys
of validations whose
status is invalid or infrastructure_failure. The observations that count
are
Each has a scale key : its scale text when present, else its
dataset_id. Group by
into the multisets of elapsed_us values. The plot of a case has one
point per group,
with the type-7 median of stats, and its
note counts (minus the failed keys) by phase. Groups, cases and
implementations keep their order of first appearance. Adding a failing
validation can only remove observations from groups, and adding an invalid,
discarded or exploratory observation changes no group: the projection is
monotone in the evidence against a timing.
Coordinates
A plot occupies the rectangle of a view box. On a categorical axis, with distinct x values in order of first appearance, value is placed at
On a linear axis every x is the text of a finite number . With and the extremes,
an increasing affine map, so the positions are in numeric order and distances
are proportional to differences of scale. Equal numbers with different text
("1e3" and "1000") share a position. The renderer sorts the values,
labels the first, and labels each next one only if it is at least 56 px to the
right of the last label, so labels never overlap.
Let and be the extreme y values. The y range is padded,
and for an empty plot. For finite values and in exact arithmetic, in every case, so the linear map
is well defined, and for every plotted value , which places every
point strictly inside the plot area. In floating point the padding can be lost
to rounding when is tiny compared with , and an infinite or
NaN value breaks the bounds; the renderer does not filter them. Heatmap cells use the opacity
, which therefore lies strictly between
and : no cell is invisible and none is fully saturated.
Grid lines are drawn at for with tick value , rounded to three decimals. On a categorical axis with values, labels are drawn every values and at the last one, so at most eleven labels are shown.
Paired blocks
Fix a case, a scale and two implementations, the baseline and the
candidate . For a block id let and be the timings of
with that block id. Block is complete when
; it gives the pair
and the paired delta . With the block ids
seen in either implementation and the complete ones,
blocks_incomplete is .
Pairing by block is what makes the comparison robust to drift. In the model of the stats design, and with a block effect shared by both implementations, so
does not contain . The runner guarantees the shared : inside a block both implementations run one batch each, on the same dataset, in a balanced order. Datasets that share a scale are pooled into one comparison; the runner numbers blocks per scale, so blocks of different datasets have different ids and never mix.
A failed validation of (or ) on dataset removes its timings of from . The blocks of then hold the other implementation only and are incomplete; no block of enters the decision. This holds for measurement validations too: their evidence names the dataset.
Outliers on paired deltas
Let be the outlier policy and its fences computed from the
multiset (Tukey: and
; MAD trim: ;
ReportOnly: the whole line). @stats.filter_outliers returns the deltas
inside the fences, and the report keeps the pairs
This selects exactly the pairs whose delta survives. The fences are fixed
once computed from all deltas, so the test "" depends
on alone. If is kept, it is in the filtered multiset. If it is
removed, every delta equal to it fails the same test, so no value equal to
is in the filtered multiset. Membership of in the filtered deltas
is therefore equivalent to being kept, and is the set of surviving
pairs, with its multiplicity. blocks_used is and
blocks_outliers is .
Why the deltas and not the raw times. A spike that hits both implementations of a block is part of and cancels in ; the block is a good pair, and filtering raw times would throw it away. A spike that hits one implementation only moves and is what the filter should catch. Filtering each implementation’s times separately would also break pairs, dropping but keeping , and the comparison would no longer be paired.
The decision and the interval
Over , with and
, the relative delta is
and the decision is the rule of
stats.compare_paired
with threshold = practical_delta_pct: Faster when and
, Slower when and , Equivalent otherwise. The
bootstrap interval of in µs/op is mapped to percent by the same
scale,
so it can be read on the axis of and . For the map
is increasing, so the order of the bounds is kept and
lies in the percent interval exactly when lies in . For
(or NaN) the map is not increasing or not defined and has no
meaning, so the row is Invalid before the bootstrap runs.
The minimum of three blocks
With pairs the median is the mean of the pairs, so one disturbed block moves it without bound, and the percentile interval is the range of the data: for every resample is ; for the resampled median is , or with probabilities , so the 2.5 % and 97.5 % quantiles are and . Neither number says anything beyond the data. From on, one disturbed block cannot move the median outside the range of the other deltas: for the median is the middle value, which lies between the two undisturbed ones whatever the third one does. Three is therefore the fewest blocks for which the report decides. The interval is still weak there: by the formula of the stats design the 95 % interval of three deltas is and covers the true median with probability , which is why the note warns that the actual coverage can be well below the nominal level with few blocks.
Row seeds
Each row is resampled with its own seed
over UTF-16 code units, with ␟ the unit separator U+001F and the run seed in
decimal. The hash uses only wrapping 64-bit arithmetic, so , and with it the
interval, is the same on every target. Rows of one report differ in at least
one of case, scale and candidate; as long as these identifiers contain no
U+001F, their key texts differ, and different texts give different seeds up
to a 64-bit collision. A per-row seed makes a row’s interval a function of
that row’s data and key only: adding a candidate, a scale or a case to the
record does not shift another row’s random stream. The prefix
mare_mark/compare/v1 versions the derivation, so a later change of scheme
cannot silently reuse old streams.
Design decisions
A pure projection with the effects outside
Problem. Reports are regenerated after renderer changes and compared in
review. Choice. document_from_jsonl, plot_json, plot_svg, html and
comparisons_text take values and return strings; file IO, standard streams
and opening a browser live in the cli. Why. The same JSONL gives
the same bytes on every target, tests need no filesystem, and the HTML can be
produced inside a larger application.
Confirmatory medians per scale
Problem. A plot of every raw observation mixes the exploratory phase, which
exists to look around, with the confirmatory one, and puts every dataset of a
scale at a different x. Choice. Plot only confirmatory observations, one
point per implementation and scale at the median of its timings, pooled over
the datasets and repetitions of that scale; count the left-out observations
in the note. Why. Decisions are made on the confirmatory phase, so the plot
shows the same data the comparisons use. The median matches the location the
decisions use and is robust to the rare large outliers timings have. Pooling
over datasets is what the experiment designs are for: the datasets of a scale
are samples of one input distribution. A record without phase predates the
field; its observations were confirmatory by intent, so they are kept. A phase
the reader does not know is excluded rather than guessed at.
The scale on the x axis
Problem. Scales are integers, shapes, layouts or names, and the x value used
to be the dataset index. Choice. The x value is the scale text the runner
records with each observation; positive finite numeric values spanning at least
100x use a logarithmic axis, other finite numeric values use a linear axis, and
non-numeric values use a categorical axis in order of first appearance. Records
without scale fall back to dataset_id, and the axis label says so. The same
rule is applied independently to y values. Why. The reader asks how time
grows with the scale; the dataset index is an artefact of the run. Linear and
logarithmic placement show numeric growth without spacing 64 and 4096 equally;
names keep their order. The fallback keeps old records readable without
pretending that a dataset index is a scale.
Failures remove timings and stay visible
Problem. A fast implementation that returns wrong results would look like a win. Choice. A failing validation removes the timings of that implementation for that case and dataset from the plot and from the comparisons, and adds a mismatch row; minimized failures add a counterexample row with the replay command. Why. The differential section sits above the plots, so the reader sees why a series is missing or a comparison has incomplete blocks.
Decisions from the record
Problem. A report that only plots leaves the decision to whoever reads it,
with whatever threshold they have in mind. Choice. document_from_jsonl
compares every implementation with one baseline, per case and scale, with the
practical_delta_pct and outlier_policy of the recorded protocol and the
recorded run seed, using stats.compare_paired_with_bootstrap; the HTML shows
the table before the plots, and the CLI prints it. Why. The run declared how
it wants to be judged; using those settings makes the decision a function of
the record, recomputable by anyone. The settings, their source and the fixed
report constants (95 %, 10000 resamples, at least 3 blocks) are stated in the
note next to the table, so a reader never has to guess what produced a
decision.
One baseline, chosen explicitly or by order
Problem. With implementations there are pairs. Choice. One
baseline per report, by default the first implementation of each case, or the
one named by baseline=; an unknown name is an error. Why. A benchmark
usually asks “is the new code faster than the current one”, which is one
baseline and rows; all pairs would multiply rows and the chance of a
spurious decision. Rejecting an unknown baseline catches typos that would
otherwise produce a table of Unknown rows.
Stated defaults for older records
Problem. Records written before the summary carried the protocol and seed
have neither. Choice. Compare them with a 1 % threshold, ReportOnly and
seed 0, mark protocol_recorded and seed_recorded false, and say so in the
note. Why. ReportOnly removes nothing, the safest choice when the run’s
policy is unknown; 1 % is the threshold of the QuickCheck and Development
presets; seed 0 is as good as any fixed seed and is printed. A malformed
protocol or seed, unlike a missing one, is an error: it is a broken
record, not an old one.
Escaping order
Text is escaped by replacing &, <, >, " and ' in this order. &
must be first: replacing it after < would turn the produced < into
&lt;. Since every later replacement introduces only & that is already
part of an entity, the result decodes back to the input exactly once. The same
function escapes element text and attribute values.
Self-contained output
The HTML embeds its CSS and inline SVG, loads no fonts, scripts or images, and
declares color-scheme: light. It can be attached to an issue or archived with
the JSONL and still render identically in ten years.
Version gate
A line whose artifact_version is a string other than mmka_1 is rejected
with its line number. Lines without the field are accepted, so hand-written
fixtures and earlier streams stay readable; a non-string version is an error.
JSON output carries schema_version mmks_2.
Correctness and invariants
- Determinism. Every function is pure; equal inputs give equal strings, including the bootstrap intervals (seeded per row).
- Exclusion. No point and no pair comes from an observation that is invalid, discarded, not confirmatory, or covered by a failing validation (definition of ).
- Pairing. A used pair holds exactly one baseline and one candidate
observation of the same case, scale and block; the outlier policy removes
exactly the pairs whose delta is outside its fences (derived above), and
blocks_used + blocks_outliersis the number of complete blocks. - Decided rows. A row is
Faster,SlowerorEquivalentonly with at least 3 used blocks, a positive baseline median and a successful bootstrap; everyUnknownorInvalidrow has a non-empty reason. - Containment. For finite values, every point lies strictly inside the plot area, and every heatmap opacity lies in (derived above).
- Escaping. All text originating from events, titles, units, series names, notes and comparison cells passes through the escape function before reaching SVG or HTML.
- Complexity. Parsing is linear in the stream size, except that each observation is checked against the list of failure keys, , and grouping searches the groups of its case. A comparison of pairs costs for the outlier membership test and with for the bootstrap. Rendering a plot with points, x values and series is because line means are recomputed per cell.
Alternatives rejected
- A JavaScript charting library. It would need scripts or a CDN and would make the output depend on a browser runtime.
- Plotting every raw observation. Mixes phases and datasets and hides the quantity the decision is about; the record keeps the raw values.
- Deciding from the interval. Would make the decision depend on the number of blocks; the decision is the practical rule on the point estimate, and the interval is shown next to it (see the stats design).
- Filtering raw times. Breaks pairs and removes blocks whose disturbance cancels in the delta (derived above).
- All pairs of implementations. More rows, more spurious decisions, and rarely the question asked.
- Treating failed implementations as zero or infinite time. Both are misleading values on a timing axis.
- One bootstrap stream for the whole report. Adding a row would change the intervals of the others.
Boundaries
- The JSONL projection builds one
Scalingplot per case. Other plot kinds are rendered when a caller constructs them in Plot IR, but nothing derives them from events. - Comparisons are against one baseline, per case and scale; pooling across scales or cases is not done.
- The confidence (95 %), the resamples (10000) and the minimum of 3 blocks are fixed by the report; the threshold, the outlier policy and the seed come from the record or from stated defaults.
- The interval does not model the dependence between neighbouring blocks that the rotation introduces, and its actual coverage with few blocks is below the nominal level.
- The target is passed in by the caller; it is not read from the stream.
- Environments are not compared: mixing records of different machines in one stream pools their observations.
- Styling, colours and layout are not a compatibility promise; the
mmks_2JSON structure is.