docs/design-notes/latency-investigation.md as planned or “worth doing eventually”. The value of writing it down is to keep the baseline honest, so that a future change can be judged against something real, and to separate what is measured from what is hypothesized.
Items in sandkiln-vmm carry path:line references verified against the current tree. Daemon items are cited the same way, for example snapshot_and_stop in core/crates/daemon/src/http/routes/snapshot.rs.
Problem and how it was found
Snapshot-take is the operation that suspends a running sandbox: pause the vCPUs, write the guest’s memory and device state to disk. It is the cost behind explicit snapshots, behind auto-suspend of idle sandboxes, and behind every warm entry a pre-warmed pool prepares. It was benchmarked when the snapshot and resume benchmarks were added in commit3b0deef, whose title records the surprise: “real numbers say resume isn’t the latency win we assumed”.
The benchmark is bench_snapshot_take in core/crates/vmm/benches/vm_lifecycle.rs. It boots a fresh VM outside the timed region, then times only the pair that the daemon’s snapshot_and_stop performs:
SANDKILN_BENCH_VCPU_COUNT, SANDKILN_BENCH_MEM_SIZE_MIB, defaults at core/crates/vmm/benches/vm_lifecycle.rs:32 and :35). What the benchmark does not time matters as much as what it does: it excludes Vm::stop and everything the daemon does around the snapshot (the HTTP layer, the bookkeeping, the lease handling).
The recorded readings, by date:
The same project-wide figure appears in the roadmap’s findings table as “310-990ms”. I could not find a recorded 990ms measurement anywhere in the repository history: the highest individual reading I can locate is 915ms. I have not used it in the table above.
Two things stand out in the table. First, the figure moved by more than 2x across readings with no code change to the snapshot path. The roadmap’s own explanation, recorded on 2026-09-14, is that the dev box is an actively used desktop and that a synchronous full-memory write is far more exposed to that than the other benchmarks. Second, the lead’s note for 2026-11-24 that the earlier 310 to 335ms figures came from “an earlier kernel/load state” is consistent with that: neither the earlier nor the later set is authoritative, and both are shown with their dates.
For contrast, resume is cheap.
resume_from_snapshot was recorded at about 25.8ms (25.5 to 26.2ms) when first measured, a mere 19 percent below that day’s cold boot of about 31.9ms. After the fixed 20ms socket-wait sleep was replaced it read 6.5 to 7.7ms, and a bench-report run on 2026-09-14 read 7.95ms. The asymmetry between take (hundreds of milliseconds) and resume (single digits) is the reason a pool makes sense at all: take is paid ahead of time, in the background; resume is paid on the request path.
The criterion benchmark times the span from Vm::pause through Vm::snapshot only. Vm::stop and the registration that follows are outside it.
Root cause
The honest statement is that the cost is explained but not profiled. Four facts are established.Vm::snapshotis thin. It is a singlePUT /snapshot/createagainst Firecracker’s API (core/crates/vmm/src/vm/snapshot.rs:40, request at:42), andVm::pauseis a singlePATCH /vm(core/crates/vmm/src/vm/snapshot.rs:29, request at:31). Sandkiln’s own code adds no copying, no compression and no encryption on this path. So the time is, as far as the code shows, Firecracker’s time.- Firecracker writes the guest’s memory to the
mem.binfile itself, in theFilebackend mode thatVm::resumeuses for loading (backend_type: File). The roadmap’s encryption section states the consequence: Firecracker opens and writesmem.binandstate.snapdirectly, so sandkiln never holds the plaintext bytes. That is a relevant constraint for any future optimization that wants to touch the bytes, such as compressing them. mem.binis sized to the guest’s configured RAM. The roadmap says it is “exactly the guest’s configured RAM size”. The default guest has 512MiB (SANDKILN_MEM_SIZE_MIB, default512), so each snapshot is a half-gigabyte file written to disk.- Firecracker’s own documentation, as summarized in the roadmap, describes the asymmetry as structural: taking a full snapshot writes every dirty memory page to disk synchronously, while resume loads memory lazily through copy-on-write. That reframes the question from “find the bug” to “measure how much sandkiln’s wrapping adds on top of an operation that is inherently this expensive”. The roadmap marks that wrapping overhead as still unmeasured.
These are plausible rates for a single synchronous write on a desktop-class machine, and the spread across them is large, which fits a disk-and-cache-bound operation rather than a CPU-bound one. They do not prove it. Nobody has profiled the snapshot write with a tool that separates the pause, the page walk, the write syscalls and the flush, and nobody has measured disk throughput on this box during the benchmark. I am therefore describing the dominant cost as “writing the full guest memory”, which is the roadmap’s attribution, supported by the file size and the code path, but not by a profile. If someone wants to check it, that is the first measurement to take.
What is not established at all: how the cost scales with guest RAM (only 512MiB has been benchmarked), how much of the time is the pause itself, and how much a guest that has touched more memory costs than an idle one (the benchmark guest is freshly booted and mostly idle).
One more correction to the record, because it affects how the cost is described. The roadmap’s findings table says snapshot-take is “full memory and disk each time”. At take time, the code does not write the disk.
Vm::snapshot records the rootfs drive’s host path, not its contents (core/crates/vmm/src/vm/snapshot.rs:37 to :39, in the doc comment), and the rootfs file stays where it is. The write at take time is the memory file plus a small device-state file. The disk enters the picture later, at resume or fork, when the daemon clones a fresh rootfs. So the “and disk” in that phrase does not describe what the timed operation does.
The change
Nothing was implemented. No snapshot-take optimization has shipped, and there is no before and after to report. What follows is the state of the candidate ideas, taken from the roadmap, with each one’s status stated as the roadmap states it.
Diff snapshots deserve the most precision because they are the obvious idea. Firecracker’s Diff snapshot type captures only memory pages dirtied since the previous snapshot rather than a full dump. The roadmap records that at least one other small Firecracker-based project chains roughly ten incremental diffs before collapsing back to a full snapshot. It then says the idea would need its own measurement on this project’s workload before any claim of a win, “not assumed to transfer automatically from someone else’s numbers”. Nothing in the repository implements it. A diff snapshot would also interact with the existing model in ways that are not worked out: a resume would need the base plus a chain of diffs, which changes what “a snapshot is two files” means across
resume, fork, time-travel restore and the archive tier.
The archive tier is the closest shipped relative, and it is easy to mistake for an optimization of this cost. It is not. SANDKILN_ARCHIVE_TIMEOUT_SECS moves a held snapshot’s state.snap and mem.bin from the hot snapshot directory onto a separate SANDKILN_ARCHIVE_DIR once the snapshot has sat unresumed that long (archive_snapshot_by_id in the daemon, driven by the idle reaper). It affects where the bytes live afterwards, not how long it takes to write them. It also never moves the rootfs. That is a real Firecracker constraint found while building it: state.snap bakes in the rootfs backing file’s absolute host path and /snapshot/load has no override for it, unlike mem_backend.backend_path, which is a genuine load-time parameter. A first version that moved all three files failed on resume with a “No such file or directory” error for the rootfs path. So archiving moves only the memory and state files, which the roadmap calls “a real, if partial, win” because mem.bin is often comparable to or larger than the rootfs copy.
Where the take cost actually lands matters for deciding whether any of this is worth doing. In a pool, take is paid once per warm slot, off the request path, by the background replenisher. For auto-suspend, it is paid when a sandbox goes idle, also off the request path. It is on the request path only for an explicit POST /sandboxes/:id/snapshot. So the cost is real but mostly hidden, which is a reason the roadmap leaves it open rather than urgent.
There is one more thing that bears on the cost a caller sees, and it was a bug, not a property of snapshots. snapshot_and_stop used to end by calling vm.stop() on a VM that had just been paused. stop begins with a best-effort sync over vsock that a paused guest cannot answer, so every snapshot waited out two sequential 3 second timeouts. The criterion benchmark does not include stop, so none of the numbers in this post showed it. Timing the HTTP request showed 6.8 seconds end to end against roughly half a second of real work. snapshot_and_stop now calls Vm::force_stop, and the same request measures 0.56 seconds. The full story is in Snapshot stop: 6.8s to 0.56s. The take cost itself (pause plus the memory write) was not changed by it.
Where the take cost is actually paid depends on the caller, which is why most of it is off the request path:
Result
Measured baseline only. These are the numbers a future change would have to beat, with the caveat that the same benchmark has read 310 to 915ms on the same hardware depending on date and load.
No snapshot-take optimization has shipped. Differences between the criterion rows are load, kernel and date, not code. The one code change that moved a caller-visible number is the stop fix, which removed a wait that sat outside the benchmark, and the 2026-11-23 re-measurement of both take and resume is directional on one shared box, like every other row.
What it cost or risks
Nothing was changed, so no change has a cost. The risks are in leaving it alone and in the candidates.- Leaving it alone: for the roadmap’s own reasons the cost is mostly off the request path, so the user-visible harm is bounded.
- The numbers are untrustworthy at the margin. A single run can read anywhere in a 3x range on this box. Any future claim of a win smaller than that range needs many runs, an isolated box, or both. The project’s own standard is to treat one shared dev box as directional only.
- Diff snapshots would change the on-disk model and the lineage semantics, and would need the memory-file chain to survive archiving, deletion of intermediate snapshots, and time-travel restore. The roadmap already notes that lineage is a parent pointer and not a durable ancestry record, so deleting an intermediate snapshot would break a diff chain in a way it does not break a full snapshot.
- Compression would sit awkwardly with the fact that Firecracker writes
mem.bindirectly. Sandkiln would have to post-process the file, adding a second pass and extra latency in exchange for smaller files, which is the opposite trade to what a latency optimization wants.
How to reproduce
The baseline, in isolation:scripts/integration-tests/25-long-running-commands.sh fails it at 3 seconds or more:
SANDKILN_BENCH_MEM_SIZE_MIB to 256 and 1024) to see whether the cost scales with RAM, which is the central assumption behind “it is the memory write”. Run either on a quiet box, several times, and report the spread and not a single value.