Python iconPythonSep 30, 2026 ~4 min source read

Memory Snapshots for CPython: proposal to speed startup with a reinitialization phase

Hood Chatham proposed using memory snapshots plus an explicit initialization phase so CPython can restore a warmed-up interpreter state while safely reintroducing runtime randomness and other per-process state.

Python Insider: Memory Snapshots for CPython (Python Language Summit 2026)

Share this story

Send the public story page.

Useful takeaways from this story.

Memory snapshots can significantly reduce Python startup time by restoring an initialized interpreter image instead of re-running initialization work.

Snapshotting is attractive for environments like WebAssembly and edge compute where startup cost and filesystem access are constrained.

Trade-offs include subtle correctness/security risks, interactions with lazy imports and freezing modules, and engineering complexity versus alternative speedups.

Primary technical problem: per-process randomness

A direct restore of an initialized process reuses values that should be unique per process. Python and many other languages randomize hash seeds at startup to mitigate hash-collision denial-of-service attacks. If a snapshot restores the same hash seed every time, dictionaries and sets become predictable across processes and the randomized-protection assumption breaks. Hood framed this as a generic issue: other libraries and runtime assumptions expect certain state to be freshly initialized on each run.

Proposal: explicit initialization phase

To address this, Hood proposed introducing an explicit initialization phase in the language model. This is an entry point run after memory restoration that can re-seed randomness and reinitialize any other per-process state. He cited RPython and SPy, which expose explicit initialization entrypoints used for similar purposes (tree-shaking, pre-evaluation). The idea is that snapshot restore would be followed by callbacks or a reinit step that ensures process-unique state is recreated safely.

  • Callbacks vs initialization phase: Stefan Behnel pointed out Python already has atexit for shutdown callbacks and asked whether a reinit callback surface might suffice. The proposal contemplates a more explicit language/runtime hook so the runtime and libraries can reliably reinitialize state.
  • Alternatives and complexity: Peter Bierma asked whether making initialization itself faster could obviate snapshotting. Hood argued that speeding initialization would be far more complex than implementing snapshot restore and reinit hooks, because initialization includes a lot of work such as importing and executing modules.
  • Freezing modules and prior attempts: The group discussed freezing or deep-freezing modules. Alibaba had prior work using memory dumps and metadata tables. Guido van Rossum noted the Faster CPython team tried deep-freezing modules and found limited startup benefits while increasing complexity.
  • Define the reinitialization entrypoint or callback API and what guarantees it must provide.
  • Inventory runtime and library state that must be re-seeded or reinitialized after restore.
  • Prototype snapshot restore workflow and run compatibility/security tests, focusing on hash randomization and other sensitive state.

More context around this story.

Keep reading in the app

Open the app view to save this story, compare related coverage, and continue from the same source.

Open in app