# dynamic-ssz benchmarks

Continuous benchmarks of SSZ libraries for Go (dynamic-ssz and others) on a
dedicated machine. Every commit of a library's main branch, every pull
request head and every release is measured on real mainnet payloads.

The pages of this site are drawn by a script; a link like
https://sszbench.pk910.de/#/job/12 returns only the script's shell. Use the text and JSON
addresses below instead. Text is Markdown; JSON carries every number.

## From a link to its data

| link in the browser | text | JSON |
|---|---|---|
| /#/job/<id> | /job/<id>.md | /api/job/<id> |
| /#/commit/<library>/<sha> (optional ?base=<sha>) | /commit/<library>/<sha>.md | /api/commit/<library>/<sha> |
| /#/repo/<library> (optional ?page=N) | /repo/<library>.md | /api/repo/<library> |
| /#/repos | /repos.md | /api/repos |
| /#/job/<id>/leaf/<Engine>/<Object>/<Op> | - | /api/job/<id>/leaf/<Engine>/<Object>/<Op> |
| /#/jobs | - | /api/jobs?limit=100&summaries=1 |
| /#/pr/<number> | - | /api/pr/<number> |
| /#/op/<Object>/<Op> | - | /api/op/<Object>/<Op> |
| /#/noise | - | /api/noise |
| /#/ and /#/ops, the libraries side by side | /ops.md (?mode=release or master) | /api/ops?mode=release or mode=master |
| /#/activity (the machine, the queue, the newest jobs) | - | /api/dashboard |
| /#/compare?a=<ref>&b=<ref> (leads to the commit page of b with a as its base) | /commit/<library>/<b>.md?base=<a> | /api/compare?a=<ref>&b=<ref> |

More: /api/job/<id>/samples (every single run of a job), /raw/<id>/<file>
(a job's log files, named on its text page), /api/status.

## What is measured

- A benchmark is Engine / Object / Operation. Objects are payload types
  (FuluState, FuluBlock, FuluBlocks, GloasState, GloasBlock, GloasBlocks,
  GloasEnvelope, and FuluMinState, FuluMinBlock, GloasMinState,
  GloasMinBlock: the state and the block cut to the minimal preset,
  measured with the minimal spec values on Unmarshal, Marshal and
  HashTreeRoot only, so that every spec value the types depend on is
  exercised at a value other than its compiled default); operations are
  Unmarshal, Marshal, HashTreeRoot and their variants. Engines of
  dynamic-ssz: Codegen (generated code) and Reflection. "HashTreeRoot
  (async)" is the hash tree root with background
  workers, an operation of each engine (the harness runs it as the engines
  CodegenAsync / ReflectionAsync, which is how the JSON names it).
- A job measures a head commit, usually against a base commit. Each side
  is built once per layout seed (the linker shuffles the functions), and a
  pass measures both sides built with the same seed. Numbers per call:
  time (ns), cycles and instructions of the measured thread (hardware
  counters, user mode), allocated bytes and allocations.
- The delta of an operation is the median over the layout seeds of
  (head - base) / base; the runs of one seed are folded into one value
  first (a seed fixes the layout, so its repeats add no new layout).
  Cycles are the primary metric (time for the async hashing, whose work
  is spread over threads).

## Reading a result

- "changed" means: the delta lies beyond the band, and at least three
  quarters of the seeds point the same way. The band is the larger of
  the operation's noise floor on this machine and twice the spread of the
  per-seed deltas divided by the root of their number. Anything inside
  the band is not a finding.
- "work" tells what kind of change it is. "code": the instructions per
  call moved beyond their own band (at least 0.5%, more for operations
  whose instruction count varies between runs; alignment padding makes it
  follow the layout a little), with three quarters of the seeds agreeing,
  so the code does different work (look at the diff for more or fewer
  instructions on that path). "same work": the instructions did not move
  but the cycles did; that comes from how the
  same code executes (function placement, cache, branch prediction) and is
  often a layout effect and not a regression of the change itself.
- Allocations and bytes per call are exact; a change there is always real.
- A single job has four layout seeds; a job page shows that job alone. A
  job's verdict in the GitHub check and comment pools every run of its
  pair, and the commit page pools every job that measured the commit
  (runs of one boot of the machine when both commits have one in common):
  those are the better source for a verdict. A new pull request head gets
  four runs (sixteen seeds) right away.

## Comparing

- Libraries with each other: /ops.md (the standings and, per payload,
  every library's time to decode, encode and hash it).
- Two commits of a library: /commit/<library>/<sha>.md?base=<other sha,
  branch or tag>. They are compared over the layout seeds both were run
  under.
- The same comparison as an image: /svg/benchmarks.svg (?theme=dark,
  ?fork=gloas, ?mode=master, ?highlight=<library>); its labels and
  values are text.

## Finding the cause of a regression

1. /repo/<library>.md: find the commit where an engine or operation moved.
2. /commit/<library>/<sha>.md: the operations that changed against the
   commit's base, pooled over all its jobs, with the kind of change.
3. /job/<id>.md of a job that measured it: the same for one job, and its
   log files.
4. /api/job/<id>/leaf/<Engine>/<Object>/<Op>: every run of one operation
   on both sides, per seed.
5. The commit itself in the library's repository (linked on each page).
