📝 The gather dispatch's cost is its own planning and four driver calls, not the descriptor set the fix was aimed at, and a content cache on that rail would serve 91% of it

x86 macOS / Linux Vulkan, macos-13, sustained-animation probe, two driven boots
under the compute gather. Documentation and harness only; no code behaviour
changed.

## `gather_phase`: 0.96 us a dispatch, and the plan was aimed at the 9%

Two boots, ~21 000 dispatches a census second each, agreeing to a hundredth of a
microsecond:

    record   0.376 us/dispatch   39 %   bind pipeline, bind set, push, dispatch
    plan     0.350 us/dispatch   37 %   two Vecs and the table's own, over ~13 runs
    stage    0.150 us/dispatch   16 %   the shared run-table arena, already amortised
    dset     0.082 us/dispatch    9 %   one vkUpdateDescriptorSets
             0.959

`env::COMPUTE_GATHER` named the **destination arena** as "the candidate that
survives the arithmetic without a reading". It attacks `dset`. Recycling the
sets — four lines, landed in 42ba8ce3 — had already taken
`vkAllocateDescriptorSets` and its matching free out of the steady state, and
what is left there is 9 % of the cost. Building the arena first would have been
a day spent on the smallest of the four columns, which is the outcome the split
was built to prevent and the reason it was built before anything else.

What is actually there: `plan` is entirely this crate's own code with no driver
call in it — three heap allocations and three passes over ~13 runs to produce
~200 bytes — and `record` is four driver calls whose count falls only with the
dispatch count. The destination arena does still buy ~30 % of `record` by
merging a draw's 1.4 dispatches into one; it buys it in a different column than
the one it was proposed for.

## `buffer_gather_working_set`: 91% recurrence, 288 MiB to hold it

    distinct=1897  mib=287.7  gathers=20771  mib_moved=3520.5  recur=0.909  dropped=0
    distinct=1781  mib=271.7  gathers=19452  mib_moved=3307.5  recur=0.908  dropped=0

An unbounded content cache would serve 91 % of the gathers — ~3.2 GB/s of GPU
copy and ~90 % of this rail's ~427 000 transfer regions a second, which is the
largest removable item in the device on `render_writeback`'s own established
arithmetic that region count and not bytes is the bound.

Three qualifications, all on the line: it is 91 % and not the 99.2 % this rail
is usually argued from (that was a window-drag probe and a census that no longer
exists — two workloads, both real, quote the one whose probe is named);
unbounded means 288 MiB held across submissions against a gather pool that is
transient today, so the cap will bind and the eviction policy is part of the
design; and `dropped=0` says 1 897 is a count rather than a floor.

Recurrence is about keys, not bytes. `runtime::gather_witness` already carries
the soundness argument this would need — the hypervisor dirty bitmap for guest
CPU stores and `runtime::host_writes` for this device's own — for the sampled
rails. Its `MAX_TRACKED_WINDOWS` is 256 against 1 897, so adopting it is a
resize as well as a wiring.

Also in this commit: `kb/harness/ranktest.py` (gitignored) now reports
`slot_us_per_draw`, `record_us_per_draw` and `dispatches_per_draw` beside the
frame metrics, and `kb/harness/analyze.py` prints the working-set line, so the
mechanism is visible in the same banded, ranked form as the outcome.

Tests: unchanged, 1931 passed / 0 failed. Clippy `-D warnings` clean on all
three arms. `cargo doc` adds no unresolved link.

Not verified: nothing on any rail but macos-13, and the two boots were taken on
a host that was quiesced but not exclusively so — the `_us` columns are upper
bounds, though the two boots agreeing to 1 % and the shares being ratios makes
the split itself robust to that.
This commit is contained in:
Anees Iqbal committed 2026-08-11 10:25:15 +03:00
1 parent b8279f90fa
commit f64205262c
2 files changed
+74

No files matched your search

@@ -34,6 +34,46 @@
//! factor and a reader comparing one to `record_us` per draw would conclude the
//! parts do not sum.
//!
//! # What it said, and why it was worth building
//!
//! Two driven macos-13 sustained-animation boots, ~21 000 dispatches a census
//! second each, agreeing to a hundredth of a microsecond:
//!
//! ```text
//! us/dispatch share
//! record 0.376 39 %
//! plan 0.350 37 %
//! stage 0.150 16 %
//! dset 0.082 9 %
//! 0.959
//! ```
//!
//! **The descriptor set is already nearly free, and the fix this crate had
//! written down was aimed at it.** `env::COMPUTE_GATHER` named the destination
//! arena — the change that makes all three bindings constant so a draw needs one
//! set instead of 1.4 — as "the candidate that survives the arithmetic without a
//! reading". It attacks the 9 % column. Recycling the sets, which cost four
//! lines, had already taken `vkAllocateDescriptorSets` and its matching free out
//! of the steady state, and what is left of `dset` is one
//! `vkUpdateDescriptorSets` of three buffers.
//!
//! The two that matter are:
//!
//! * **`plan`, and it is entirely this crate's own code.** No driver call is in
//! it: a `Vec<ScatterRun>` built from the copy regions, a second `Vec` inside
//! [`super::guest_scatter::build_gather_run_tables`] holding those runs with
//! their two indices exchanged, and the table's own `Vec<u32>` — three heap
//! allocations and three passes over ~13 runs, to produce ~200 bytes.
//! * **`record`, which is four driver calls** — bind pipeline, bind set, push,
//! dispatch. The pipeline bind is the same handle every time and only the
//! first of a draw's dispatches needs it. Beyond that this column falls only
//! with the dispatch *count*, which is what the destination arena would buy
//! after all — 1.4 down to 1.0, so ~30 % of it, and not the 9 % column it was
//! proposed for.
//!
//! `stage` at 0.150 is the shared run-table arena, already amortised over a
//! draw's 1.4 dispatches, and there is nothing left in it to remove.
//!
//! # This measures the planning, not the copy
//!
//! Every part here is CPU time spent *arranging* a copy the GPU makes later, in
@@ -41,6 +41,40 @@
//! one. Both are on the same line for that reason, and `gathers` beside them is
//! what makes the recurrence rate readable as `1 - distinct / gathers` for this
//! window rather than quoted from a boot nobody can re-run.
//!
//! # What it said
//!
//! Two driven macos-13 sustained-animation boots, a census second each:
//!
//! ```text
//! distinct=1897 mib=287.7 gathers=20771 mib_moved=3520.5 recur=0.909 dropped=0
//! distinct=1781 mib=271.7 gathers=19452 mib_moved=3307.5 recur=0.908 dropped=0
//! ```
//!
//! Three things follow and they do not all point the same way.
//!
//! * **A cache of unbounded size would serve 91 % of the gathers**, which is
//! ~3.2 GB/s of GPU copy and ~90 % of this rail's ~427 000 transfer regions a
//! second. That is the largest single removable item this device has, on the
//! arithmetic that `render_writeback`'s own ablation established — region
//! count, not bytes, is what the rail is bound by.
//! * **It is 91 % and not the 99.2 % the buffer rail is usually argued from.**
//! The older figure came off a window-drag probe and a census that no longer
//! exists; this is the sustained-animation population. Quote the one whose
//! probe is named, per `AGENTS.md`: they are two workloads and both are real.
//! * **Unbounded means 288 MiB of device-local memory**, held across
//! submissions, on a host whose whole gather pool is transient today. That is
//! the number a cap has to be argued against, and it is large enough that the
//! cap will bind — so the eviction policy is part of the design and not a
//! detail to add later. `dropped=0` says the 1 897 is a count and not a floor.
//!
//! Recurrence is about **keys**, not bytes: it says the same window comes back,
//! not that its contents are unchanged. What would make a hit sound is
//! [`crate::runtime::gather_witness`], which already carries exactly this
//! argument for the sampled rails — the hypervisor dirty bitmap for guest CPU
//! stores and [`crate::runtime::host_writes`] for this device's own. Its
//! `MAX_TRACKED_WINDOWS` is 256 against the 1 897 here, so adopting it is a
//! resize as well as a wiring.
use std::collections::HashMap;