1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! Bench-only debug counters for Arc-clone / COW-copy events (issue #821
//! Workstream B seed, `docs/runtime-bench.md`).
//!
//! The value model's performance claims (`docs/value-model-spec.md` §5/§6)
//! rest on two mechanisms: sharing a collection is an O(1) `Arc::clone`, and
//! mutating a shared collection pays exactly one O(n) copy (via
//! `Arc::make_mut` inside `Value::array_make_mut`/`map_make_mut`/
//! `record_make_mut`) before becoming unique again. Wall-clock benchmarks
//! can only *infer* whether these mechanisms actually fired; these counters
//! measure it directly.
//!
//! This entire module exists only when the `bench-counters` feature is
//! enabled — it is not part of the `default` feature set, so `cargo build
//! -p brink-runtime` (no extra flags) never compiles it in: there is no
//! `bench_counters` module, no atomics, no call-site branches — a
//! compile-time cut, not a runtime toggle. The call sites in
//! `collection_ops.rs`/`record_ops.rs`/`vm.rs` that report into this module
//! do so through tiny `note_*` wrapper functions that are themselves
//! `#[cfg]`-gated to a no-op empty body when the feature is off, so the
//! wrapper call inlines away to nothing (verified by the gate: `cargo build
//! -p brink-runtime`/`cargo clippy` with no `bench-counters` feature builds
//! clean with the module physically absent).
use ;
static COW_COPIES: AtomicU64 = new;
static ARC_CLONES: AtomicU64 = new;
/// A point-in-time read of the counters. Cheap `Copy` value so benches can
/// snapshot before/after a measured section and diff.
/// Record one COW copy event.
/// Record one Arc-clone (cheap share) event.
/// Read the current counter values without resetting them.
/// Zero both counters. Benches call this before the measured section so
/// setup work (compiling, linking, building initial fixtures) doesn't
/// pollute the count.