test: load-insensitive tviews perf gate; env note
This commit is contained in:
+36
-23
@@ -534,29 +534,42 @@ suite "egress borrows the world instead of copying it (#28)":
|
||||
test "building a Context and egressing does not scale with the explored sets":
|
||||
var small = bigStore(16384) # 128 x 128 cells: the v1 map at cell 32
|
||||
var large = bigStore(262144) # 512 x 512 cells: a 16384 px map at cell 32
|
||||
# A build is six addresses. Before the fix, one Context construction cost ~0.19 ms at 16384
|
||||
# cells and ~4.44 ms at 262144 (the issue's measurement on this build's types).
|
||||
var sink = 0
|
||||
var t0 = getMonoTime()
|
||||
for i in 0 ..< 1000: sink += large.borrow.pTokens[].len
|
||||
let buildMs = float((getMonoTime() - t0).inNanoseconds) / 1e6 / 1000.0
|
||||
echo &"#28 context build, 262144 cells x 6 players: {buildMs * 1000.0:.3f} us"
|
||||
check buildMs < 0.01 # 10 us; a copy of one explored set is already ~0.55 ms
|
||||
# Egress for 6 x 40 entries: the M5 p99 budget is 7.5 ms per mutation (DESIGN 13 M5).
|
||||
t0 = getMonoTime()
|
||||
for i in 0 ..< 20: sink += gmPass(large)
|
||||
let gmMs = float((getMonoTime() - t0).inNanoseconds) / 1e6 / 20.0
|
||||
t0 = getMonoTime()
|
||||
for i in 0 ..< 20: sink += playerPass(large, Pid)
|
||||
let playerMs = float((getMonoTime() - t0).inNanoseconds) / 1e6 / 20.0
|
||||
echo &"#28 egress, 262144 cells x 6 players x 40 entries: GM {gmMs:.3f} ms, player {playerMs:.3f} ms"
|
||||
check gmMs <= 7.5
|
||||
check playerMs <= 7.5
|
||||
# The same pass at the v1 size must be cheaper still, never a cliff: the cost follows the
|
||||
# frames, not the explored cells (before the fix the two sizes differed by ~20x).
|
||||
t0 = getMonoTime()
|
||||
for i in 0 ..< 20: sink += gmPass(small)
|
||||
let smallMs = float((getMonoTime() - t0).inNanoseconds) / 1e6 / 20.0
|
||||
echo &"#28 egress, 16384 cells x 6 players x 40 entries: GM {smallMs:.3f} ms"
|
||||
# Wall-clock gates are load-sensitive, so every number below is the *fastest* timed sample
|
||||
# after a warm-up, never a mean: a sample the OS descheduled (or a parallel build on the same
|
||||
# box) is slow and simply is not the minimum, while a real regression raises every sample. The
|
||||
# absolute averages are recorded by `devbox run bench` (TESTING 5.3), not asserted here.
|
||||
proc minPassMs(rounds, reps: int, f: proc()): float =
|
||||
## `f` `reps` times per sample, `rounds` samples; returns the fastest sample per pass.
|
||||
for i in 0 ..< rounds: f() # warm-up
|
||||
result = 1e9
|
||||
for r in 0 ..< rounds:
|
||||
let t0 = getMonoTime()
|
||||
for i in 0 ..< reps: f()
|
||||
result = min(result, float((getMonoTime() - t0).inNanoseconds) / 1e6 / float(reps))
|
||||
const BuildBudgetMs = 0.010 # 10 us for one Context construction
|
||||
const PassBudgetMs = 2.0 # one egress pass, see below
|
||||
const LoadTolerance = 2.0 # documented slack: the minimum still rises ~1.7x on a saturated box
|
||||
# A build is six addresses. Before the fix, one Context construction cost ~0.19 ms at 16384
|
||||
# cells and ~4.44 ms at 262144 (the issue's measurement on this build's types), so 2x the
|
||||
# 10 us budget (20 us) still fails a copy regression by an order of magnitude.
|
||||
let buildMs = minPassMs(5, 100, proc() = sink += large.borrow.pTokens[].len)
|
||||
echo &"#28 context build, 262144 cells x 6 players: {buildMs * 1000.0:.3f} us (min of 5 x 100)"
|
||||
check buildMs <= LoadTolerance * BuildBudgetMs
|
||||
# Egress for 6 x 40 entries. Stated per-pass budget: 2 ms of the M5 7.5 ms whole-mutation p99
|
||||
# (DESIGN 13 M5; the #28 shape measured GM 0.79 ms / player 0.32 ms on the reference run and
|
||||
# ~1.7 ms in a debug build on a dev box). The gate allows 2x that (4 ms) because the *minimum*
|
||||
# still rises on a saturated box; a 20x regression (tens of ms) fails by an order of magnitude.
|
||||
# The absolute averages are recorded in results/bench.log (`devbox run bench`), not here.
|
||||
let gmMs = minPassMs(20, 1, proc() = sink += gmPass(large))
|
||||
let playerMs = minPassMs(20, 1, proc() = sink += playerPass(large, Pid))
|
||||
echo &"#28 egress, 262144 cells x 6 players x 40 entries: GM {gmMs:.3f} ms, player {playerMs:.3f} ms (min of 20)"
|
||||
check gmMs <= LoadTolerance * PassBudgetMs
|
||||
check playerMs <= LoadTolerance * PassBudgetMs
|
||||
# The same pass at the v1 size must be no dearer, never a cliff: the cost follows the frames,
|
||||
# not the explored cells (before the fix the two sizes differed by ~20x). Both sides are
|
||||
# minima, so the invariant holds under external load too.
|
||||
let smallMs = minPassMs(20, 1, proc() = sink += gmPass(small))
|
||||
echo &"#28 egress, 16384 cells x 6 players x 40 entries: GM {smallMs:.3f} ms (min of 20)"
|
||||
check smallMs <= gmMs * 3.0 + 0.5
|
||||
check sink >= 0
|
||||
|
||||
Reference in New Issue
Block a user