fps: Leave the readout clock's own frame out of the readings - #3025
Merged
Merged
Conversation
The clock dirties the window every 500ms to move the digits, and the draw that answers was sampled as one of the application's frames — a cold frame every 500ms feeding `FRAME`, `P95`, `DROP` and `MAX`, half the samples on an idle window. The clock now announces each notify to the sampler, which drops the first draw after it unless that draw also carried an invalidation of the application's own. Notifies are counted rather than flagged so a window the platform is not drawing, which accumulates one per tick, still reads its single answering draw as the HUD's. Also brings `crates/fps/README.md` in line with the HUD since the `continuous` mode and the rate grading were removed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
linruohan
pushed a commit
to linruohan/gpui-component
that referenced
this pull request
Sep 11, 2026
…dge#3025) ## Summary The HUD's readout clock dirties the window every 500ms to move its digits. To GPUI that is an invalidation like any other — the window is drawn in full and the frame trace records the draw — and the sampler then counted that draw as one of the application's frames. On a window with nothing to redraw it is a cold frame every 500ms feeding `FRAME`, `P95`, `DROP` and `MAX`; idle, it can be half the samples. longbridge#2954 stopped the HUD from *driving* the frame loop. This is the one frame it still causes, and until now it was measured as if the application had asked for it. ## Changes - **`FrameSampler::expect_own_frame(at)`** — the clock announces each notify before it lands. The first draw whose `draw_start >= at` is the one that answered it; if its `invalidations` count is no more than the clock's unanswered notifies, the HUD was the only thing that wanted that frame and it is not sampled. Coalesced with an invalidation of the application's own, it stays — the work was wanted, so the cost counts. - **Notifies are counted, not flagged.** A window the platform is not drawing — occluded, minimized — accumulates one per tick, and the draw that finally answers carries all of them; a boolean would have read that draw as the application's. - **Presents are untouched.** `FPS` and `INTERVAL` still count the HUD's frame among what reached the screen, which it did. - **Docs.** `website/docs/fps.md` (+ zh-CN) say so under *What the HUD itself costs*. `crates/fps/README.md` is brought in line with the HUD as it is since longbridge#2944 / longbridge#2954 / longbridge#2956: the `.continuous(true)` example no longer compiled, the `### continuous` section described a removed option, and two notes still explained the rate grading those PRs took out. The `INV` row's comment loses its `continuous` reasoning too. Why `invalidations` is the right test: `WindowInvalidator::record_frame_dirty` increments on every notify, not on the clean→dirty transition, so "the clock's notifies were the only invalidations this frame carried" is exactly `invalidations <= notifies`. ## Test plan - [x] `cargo test -p gpui-fps` — 29 pass, 4 new: the draw answering the clock is not a sample; a frame the application also asked for stays; a frame drawn before the tick is the application's; several unanswered ticks are still one frame of the HUD's - [x] `cargo clippy -p gpui-fps --all-targets -- -D warnings`, `cargo fmt --check` - [x] Window idle: `FRAME` / `MAX` stop moving at the clock's 500ms cadence; scrolling reads as before Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Summary
The HUD's readout clock dirties the window every 500ms to move its digits. To GPUI that is an invalidation like any other — the window is drawn in full and the frame trace records the draw — and the sampler then counted that draw as one of the application's frames. On a window with nothing to redraw it is a cold frame every 500ms feeding
FRAME,P95,DROPandMAX; idle, it can be half the samples.#2954 stopped the HUD from driving the frame loop. This is the one frame it still causes, and until now it was measured as if the application had asked for it.
Changes
FrameSampler::expect_own_frame(at)— the clock announces each notify before it lands. The first draw whosedraw_start >= atis the one that answered it; if itsinvalidationscount is no more than the clock's unanswered notifies, the HUD was the only thing that wanted that frame and it is not sampled. Coalesced with an invalidation of the application's own, it stays — the work was wanted, so the cost counts.FPSandINTERVALstill count the HUD's frame among what reached the screen, which it did.website/docs/fps.md(+ zh-CN) say so under What the HUD itself costs.crates/fps/README.mdis brought in line with the HUD as it is since fps: Sustain frames by default, and stop grading the rate #2944 / fps: Derive the headline rate from frame cost instead of driving the frame loop #2954 / fps: Cap the headline by asking the platform what the panel runs at #2956: the.continuous(true)example no longer compiled, the### continuoussection described a removed option, and two notes still explained the rate grading those PRs took out. TheINVrow's comment loses itscontinuousreasoning too.Why
invalidationsis the right test:WindowInvalidator::record_frame_dirtyincrements on every notify, not on the clean→dirty transition, so "the clock's notifies were the only invalidations this frame carried" is exactlyinvalidations <= notifies.Test plan
cargo test -p gpui-fps— 29 pass, 4 new: the draw answering the clock is not a sample; a frame the application also asked for stays; a frame drawn before the tick is the application's; several unanswered ticks are still one frame of the HUD'scargo clippy -p gpui-fps --all-targets -- -D warnings,cargo fmt --checkFRAME/MAXstop moving at the clock's 500ms cadence; scrolling reads as before