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
//! A global op-count **work meter** — the deterministic engine behind the
//! complexity gate (`document.rs`'s `perf_gate` matrix).
//!
//! Instrumented hot-path primitives (`Buffer::offset_to_point`/`point_to_offset`,
//! `Patch::map_offset`/`map_many`, the bracket enclosing walk,
//! `FoldMap::display_position`, `FoldMap::new`, every document-scale
//! `sort`/`retain`/`dedup`) charge the meter by the *units of work they touch*.
//! A matrix test runs each representative editor operation at 2× every scale
//! dimension (document size, caret count, fold count) and asserts the meter grows
//! within that operation's declared budget. So an accidental superlinear
//! hot-path cost fails the build instead of surfacing as field lag; a new slow
//! function is caught even though no one wrote a counter for it, because it
//! necessarily runs through these primitives. The few genuinely inherent
//! superlinear costs (an unbalanced-bracket cascade to end-of-file, a
//! fold-break `retain`) are the matrix's documented exceptions.
//!
//! Machine-independent and deterministic: it counts operations, not wall-clock,
//! so the thresholds are stable across machines and runs. Live only under
//! `debug_assertions`/`test`; the release [`charge`] is an empty
//! `#[inline(always)]` no-op the optimizer erases along with its argument, so the
//! instrumentation is zero-cost in shipped builds.
thread_local!
/// Charge `units` of work to the thread's meter (debug/test only).
pub
/// Release build: a no-op the optimizer erases (its argument included).
pub
/// The meter's current value. Only the `perf_gate` matrix reads it, so it is
/// gated to tests (the `charge` sites, by contrast, live in any debug build).
pub
/// Reset the meter to zero before a measured operation (tests only).
pub