Graph follower performance review
Reviewed source: b446c20, including the OCI/CLI runner and sealed-image check. Heimdall uses Mimir's graphs. A complete input graph is required; these optimizations do not establish that an arbitrary input is complete.
Preparation and execution
Before attachment, heimdall-graph/src/tables.rs enumerates reachable sets of possible graph positions and assigns each set an integer state. It builds two transition tables keyed by (state, syscall):
NEXTadvances to the possible positions after a different syscall. A missing transition refuses that step.AGAINhandles repeated calls using the graph's repeated-call semantics. A missing entry retains the current position; it is not the same as missingNEXT.
The integer is a name for a set of possible positions, not a program counter. Several possible branches can therefore remain represented after a syscall. The kernel does not traverse those branches or construct that set at runtime. The four base calls have separate handling, including signal return.
The loader validates bounds and sorted, unique transitions before allocating kernel maps. It sizes NEXT and AGAIN to their actual row counts, with one entry minimum for an empty map. The combined transition budget is 1,048,576 rows; oversize input is refused. This caps storage, not preparation time or the inherent possible growth of subset construction.
On an ordinary followed syscall, the BPF program checks task selection and admission state, obtains the thread cursor through STATES.get_ptr_mut, uses one NEXT or AGAIN lookup for a non-base call, and updates the cursor in place. That is one transition lookup, not one total BPF map lookup: selection, pending-event bookkeeping, optional instrumentation and receipt counters add work on entry and exit.
Allocation, copying and data structures
| Part | Current implementation | Consequence |
| Kernel cursor | Eight fixed (state, last syscall) frames, depth and entry flag; 72 bytes of integer payload |
No Rust heap allocation or graph-size-dependent cursor copy on an ordinary call |
| Kernel transitions | BPF hash maps; 8-byte key and 4-byte value before kernel overhead | Sparse storage and expected constant-time lookup; cache locality and collisions still matter |
| Thread lifecycle | Preallocated bounded task maps; fork copies the small cursor | Not literally zero-copy across all events; exhausted capacity must fail closed |
| Receipt counts | Shared atomic decision/violation counters per attachment | Potential cache-line contention across workload threads; single-thread timing does not establish scaling |
| Graph preparation | HashMap, BTreeMap, BTreeSet, vectors, work queue and cloned position vectors |
Allocations and set work occur before execution; large-graph startup and peak memory need separate measurements |
| Kernel loading | One userspace map insertion per transition row | Copies data into kernel maps and makes per-row setup calls; not zero-copy loading |
| OCI preparation | Parent preflight and shim revalidation construct tables; compilation and host preparation clone follower tables | Extra startup work and retained copies; removing them requires preserving pin validation and child launch behavior |
Both the BPF program and shared follower core are no_std. This supports the specific claim of no Rust heap allocation in the follower, not a claim that the whole kernel syscall path never allocates. Default BPF hash-map flags preallocate entries; their memory cost includes kernel metadata beyond the payload sizes above.
prepared.rs also offers dense, row-offset, compact-column and shared-row Rust layouts, and minimize.rs provides conservative graph/state reduction. These are experiments. GraphFilter::new currently calls the ordinary table builder; the kernel loader still installs hash maps. There is no evidence here that a dense layout or minimization is already active in the production path.
Measurement scope
The historical measurements in graph-filter.md are +131.5 ns and +193.9 ns per audited non-base call for different pinned objects/configurations. They are aggregate paired fixture deltas, not a direct regression comparison or syscall-latency percentiles.
The current-object paired measurement uses a fresh disposable VM, one guest CPU for the benchmark, cgroup selection, an identical static floor and clone guard, alternating run order and a discarded warmup pair. Timed runs disable optional observation and visibility counters, but retain the follower's receipt counters. Table setup, OCI startup and initial-exec admission are outside the timed interval.
On the quieter t14s, 15 paired samples measured +210.654 ns per audited non-base call, median, ranging from +140.493 to +248.202 ns. Each run made 60,080 audited calls; every Enforce run completed with zero violations and zero kills. The guest used Linux 6.8.0-139 and an AMD Ryzen AI 7 PRO 360. The loaded maps held 28,577 NEXT rows and 3,206 AGAIN rows.
The same artifacts on busy dwarf measured a median +915.690 ns, with pairs ranging from -3,724.903 to +4,486.039 ns. Host load was about 25 on 12 visible CPUs. Keep this run as evidence of measurement noise, not a useful estimate of follower cost. Negative deltas do not mean following speeds up syscalls. Both guests were stopped after collecting the reports.
Artifacts: gate SHA256 45dbd244d35c2956ccb44d6cdcfe2bf8caa84257535ca6bff3e6371094f44980, BPF SHA256 048bb51c206257b86568635d7f76be761cace8aad3716e58bf9397f98ee5ea3c. These are the exact independently rebuilt gate and BPF used by the sealed-image follow-up. This is the current follower object's fixture cost, not an OCI or CLI end-to-end timing. The difference from the earlier t14s median is not an isolated code-regression experiment: the older object was not rerun in this same guest.
Receipts, including all raw timing pairs:
For reproduction, use the pinned gate/BPF/fixture build recipes in runtime/graph-events at b446c20 and the exact graph/executable pins in the guest driver. Copy that driver to guest-cost.sh beside benchmark-fixture.py and the named artifacts in a fresh disposable guest. Mount tracefs/debugfs inside the guest, then run sudo env HEIMDALL_TEST_VM=1 bash ./guest-cost.sh. It checks cgroup selection and identical clone guards in all 33 raw reports as well as the benchmark's floor, artifact and completion checks. All 30 retained pair deltas across the two guests were independently recomputed from the raw elapsed times.
Still open: preparation time and peak memory on large graphs, actual OCI/CLI startup, multi-thread contention, unrelated-task overhead, and PostgreSQL. The fixture has a complete controlled graph; it does not establish any of these properties for a general workload.
Next optimization decisions
Measure before changing the kernel layout. First quantify startup table construction/loading and duplicate table storage. Then compare hash versus compact/dense layouts using identical transition semantics and forbidden-order controls. Measure shared-counter contention with multiple workload threads before considering per-CPU accounting; any replacement must preserve loss, overflow and diagnostic checks. Keep input completeness separate from speed.