Repository navigation
perf(replicated_state): Fill a loaded log memory store's first-timestamp cache on first use - #12192
Merged
Merged
Conversation
…amp cache on first use Loading a log memory store from a checkpoint no longer reads its ring buffer to fill the first-timestamp cache; the first `first_timestamp` call does. Validating a checkpoint loads every canister only to compare and drop it, and that read mapped each store's overlay file, which dropping it then had to unmap: 0.6 ms per canister, about 4 s of validation with 200k canisters. Clones share the cache until either is mutated, so the value filled when observing a committed state's metrics carries over to the next round's state. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the lazy timestamp-cache change.
No open issues 🎉
What changed in this PR
This PR defers initializing a checkpoint-loaded log store’s first-timestamp cache until first use, reducing checkpoint validation overhead and the related shutdown wait.
Changes:
- Initialize the timestamp cache lazily instead of reading the ring buffer during loading.
- Share the cache across clones, replacing it on mutation to preserve isolation.
- Add tests for lazy initialization, cache sharing, and clone mutation isolation.
| File | Description |
|---|---|
rs/replicated_state/src/canister_state/system_state/log_memory_store/tests/log_memory_store.rs |
Tests lazy cache initialization and isolation after clone mutation. |
rs/replicated_state/src/canister_state/system_state/log_memory_store/mod.rs |
Implements the shared lazy cache and updates mutation handling and documentation. |
Review effort: Balanced
|
✅ No security or compliance issues detected. Reviewed everything up to 9476c81. Security Overview
Detected Code Changes
|
eichhorl
reviewed
Nov 20, 2026
eichhorl
reviewed
Nov 20, 2026
…oads Since loading a log memory store reads nothing from its ring buffer, a full checkpoint load (at startup, or after state sync) read every store's header in `ReplicatedState::new_from_checkpoint`, one canister at a time, summing the cold canisters' memory usage. The loader threads now fill each store's header and first-timestamp caches as they load it, as loading did before. Validating a checkpoint still reads nothing. A store's header cache is now also set to empty after `clear` finds no ring buffer, and after `deallocate`, like its first-timestamp cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
eichhorl
approved these changes
Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Loading a canister from a checkpoint rebuilds its log memory store's first-timestamp cache by reading the ring buffer, which maps the store's overlay file; dropping the loaded state then has to unmap it. Validating a checkpoint loads every canister only to compare and drop it: with 200k canisters, each drop took 0.57–0.65 ms, mostly in
munmap, waiting for the replica's memory map lock and flushing TLBs.This leaves the cache empty on load and fills it on the first
first_timestampcall. Clones share it until mutated (every mutation sets a fresh one), so the value the background metrics observation fills in a committed state is there in the next round's state too, instead of being recomputed every round.Full checkpoint loads (at startup, or after state sync) still fill both the header and first-timestamp caches, in the loader threads:
ReplicatedState::new_from_checkpointsequentially reads every cold canister's header (for its memory usage), and the retention metric requires every store's first timestamp. Only validation leaves them empty.On a testnet node with 200k canisters under load, dropping a loaded canister takes 3.2 µs instead of 634 µs, and validating a checkpoint 15.0 s instead of 19.2 s; most of the rest is
syncfs, waiting for the protobufs' writeback. That also shortens the shutdown wait for the latest checkpoint's verification (#12094).🤖 Generated with Claude Code