untainer
Get started

Chunks and lazy loading

Layers are cut into 256 KiB chunks named by their SHA-256; a container downloads only the chunks it reads.

A layer is cut into chunks of 256 KiB, each compressed with zstd and named by the SHA-256 of its content. The guest reads the layer through a loop device from a file the host serves; each read is answered from the chunks it touches, which are loaded the first time.

#Where a chunk comes from

the cache of decompressed chunks (16 MiB by default, shared by the images of a process);
the store of compressed chunks: dirStore() on Node (~/.cache/untainer/chunks), OPFS or IndexedDB in a browser (browserStore()), or any object with get, put and has;
the image's source: its directory, or HTTP.

Every chunk is decompressed and checked against its hash before any byte of it is used: a damaged chunk is ERR_CHUNK_HASH, never data, and a damaged copy in a store is fetched again. A second start of an image fetches only its manifest.json.

#A start, measured

A first visit in Chrome, from a server on the same machine, with the image laid out by its start:

ImageReadyRequestsDownloaded
node:24-alpine0.8-0.9 s1333.9 MB
postgres:17-alpine (initdb included)5.9 s1229.2 MB

"Downloaded" is everything the page fetched: the image's part and untainer's own files, the kernel among them. Of node:24-alpine's 33.9 MB, 19.2 MB is the image (its boot bundle), out of 60.3 MB of chunks. The server is local, so the times are the guest's work, not a network's.

The boot bundle is what keeps the requests few: the chunks the start reads come in a few large files instead of one request each. What the container reads later is fetched chunk by chunk.

Measured by spikes/21-stores/browser.mjs; the runs are in docs/findings.md, "Cold start in Chrome".

#Decoding

Decompressing and hashing happen with node:zlib on Node, and in a dedicated worker in a browser, so the page's thread never does it.

untainer  OCI images as containers in a browser tab or in Node.