state: reduce statistics clock overhead - #14432
Open
shayonj wants to merge 1 commit into
Open
Conversation
EtiennePerot
approved these changes
Aug 26, 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.
I was profiling checkpoint and restore for object-heavy sandboxes and found that
state.(*Stats).sampleconsumed 210 ms of cumulative CPU during a restore with 20,000 open regular files, including 190 ms intime.runtimeNow. State statistics calltime.Nowfor every nested encode and decode interval even though they retain only elapsed durations.This change uses gVisor’s existing
gohacks.Nanotimewrapper for those samples. The current calculation already uses the monotonic component oftime.Time, so the behavioral change is limited to avoiding wall-clock acquisition andtime.Timeconstruction. The publicStatsAPI, per-type counts, timing table, and checkpoint format remain unchanged. This adds no option, alternate state path, or application hot-path work.The object-heavy test used a checkpointable Go service with a 64 MiB heap. It created 5,000 small regular files and kept every file descriptor open across checkpoint and restore, so the file count represents live file-description state processed by the encoder and decoder rather than files merely present in the filesystem. Across six alternating pairs, checkpoint time dropped by 7.73%, checkpoint CPU dropped by 10.27%, restore start time dropped by 10.13%, and restore CPU dropped by 8.99%. The 20,000-open-file restore profile reduced cumulative
Stats.sampleCPU from 210 ms to 110 ms. An empty-state control remained within run variation, so the expected benefit is small for simple state graphs. The 20,000-open-file checkpoint CPU result was noisy and is not included in the improvement claim.