mjdi docsv0.10.0latest
Performance benchmarks (P1-17)
The benchmark suite measures every resolution path plus the compile-time
Source: mjdi/docs/performance.md
The benchmark suite measures every resolution path plus the compile-time validation cost, with a reproducible methodology and recorded baseline-versus-current results.
The suite
benchmarks/bench_resolution.mojo— transient resolution (a nested three-layer graph), singleton resolution (cache hit), singleton cold cycle (miss + construct + release), scoped resolution (cache hit), scope lifecycle (create + resolve + close), factory resolution, cached factory resolution, alias resolution, and thewith_scopeguard lifecycle.benchmarks/bench_compile_check.mojo— a twelve-service nested graph whose validation elaborates at container construction;mojo buildof it measures the compile-time validation cost.scripts/run_benchmarks.sh— runs the resolution benchmarks three times, reports medians, and times three builds.
Run from the project root:
scripts/run_benchmarks.sh
mojo run -I . benchmarks/bench_resolution.mojo
Methodology
- every measured operation goes through an
@inline(.never)helper — without that guard Mojo's optimizer removes the observable effect of the resolution and the measurement collapses to zero (this is not theoretical: naive loops measure ~0 ns/op on this compiler); - warmup run before measurement (canonical instances construct and cache once);
- 50,000 iterations per benchmark, median of 3 runs;
perf_counter_nsfromstd.time;- single quiet CPU, toolchain Mojo 1.2.0 (2016d0cd) via pixi.
Recorded results
See benchmarks/RESULTS.md for the current
table (hardware, toolchain, and the v0.7.0-baseline comparison).
Headline facts, in brief:
- the nested transient wiring path is unchanged between v0.7.0 and v0.8.0;
- compile-time graph validation cost is unchanged (within noise);
- guarded resolution paths gained the re-entrancy guard's per-operation
cost (flag check + index-stack push/pop + try/except frame, ~7 ns on
hit paths; one reserved flag-list allocation per guarded
Container/Scope construction) — the accepted architectural
justification is P1-20 itself: the guard detects custom-construction
resolution cycles compile-time validation cannot see. It is a
one-parameter opt-out:
Container[type_of(reg), traced=False, collect_stats=False, reentrancy_guard=False]; - tracing and statistics are comptime-gated specializations: their recording code compiles away entirely when disabled (identical default-path numbers with and without the parameters).
Detecting regressions
Re-run scripts/run_benchmarks.sh on quiet hardware before/after a
change and compare the medians against
benchmarks/RESULTS.md. For a baseline
tree, check out the baseline commit, copy benchmarks/ into it, and
run the same commands on the same machine.
Related
- Re-entrancy — what the guard costs and buys.
- Lifecycle tracing / Cache statistics — what the specializations cost when enabled (and what they cost disabled: nothing).