Skip to main content

Module perf

Module perf 

Source
Expand description

Performance truth: process-wide counters of the work that must happen once (a repository scan, an index build, a registry build, a schema generation, a projection build) and of the work that happens per call (executions, handler invocations, cache hits and misses), plus phase timings on a monotonic clock. They are what the structural tests read after hundreds of requests to prove that no request rebuilt canonical state, what perf.counters answers over every transport, and what the benchmark evidence carries beside its latencies. Atomics only: reading them costs nothing worth measuring, and nothing here allocates on a hot path.

§What the counters are for

They exist to make one class of regression visible that no functional test can see: a change that makes every request correct and rebuilds the index to get there. The startup counters must stay at their post-startup values however many requests arrive, and tests/hot_path.rs asserts exactly that. project.hot-path-reads-once is the rule.

use majordomus_cli::perf::{Counters, Phase, COUNTERS};

// a phase is timed by a guard, so the timing ends when the work does and not later
let before = COUNTERS.snapshot();
{
    let _timing = majordomus_cli::perf::phase(Phase::IndexBuild);
    Counters::bump(&COUNTERS.index_builds);
}
let after = COUNTERS.snapshot();
assert_eq!(after.index_builds, before.index_builds + 1);

// and what happened once at startup is reported apart from what happens per call
assert!(after.startup_work().iter().any(|(name, _)| *name == "index_builds"));

Structs§

CounterSnapshot
The counters and phase totals of this process at one moment. Every value is a count or a duration this process measured; none is written anywhere by hand.
Counters
One counter per unit of work. Each is incremented at exactly one place in the code, named in its doc comment.
PhaseGuard
Times one phase from creation to drop.
PhaseTotals
A phase’s totals.

Enums§

Phase
The phases timed. Each has one owner in the code, named in its doc comment.

Statics§

COUNTERS
The counters of this process.

Functions§

phase
Time a phase until the guard drops.