Allow users to customize history length in FrameTimeDiagnosticsPlugin
#17259
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.
Objective
I have an application where I'd like to measure average frame rate over the entire life of the application, and it would be handy if I could just configure this on the existing
FrameTimeDiagnosticsPlugin
.Probably fixes #10948?
Solution
Add
max_history_length
toFrameTimeDiagnosticsPlugin
, and becausesmoothing_factor
seems to be based on history length, add that too.Discussion
I'm not totally sure that
DEFAULT_MAX_HISTORY_LENGTH
is a great default forFrameTimeDiagnosticsPlugin
(or any diagnostic?). That's 1/3 of a second at typical game frame rates. Moreover, the default print interval forLogDiagnosticsPlugin
is 1 second. So when the two are combined, you are printing the average over the last third of the duration between now and the previous print, which seems a bit wonky. (related: #11429)I'm pretty sure this default value discussed and the current value wasn't totally arbitrary though.
Maybe it would be nice for
Diagnostic
to have awith_max_history_length_and_also_calculate_a_good_default_smoothing_factor
method? And then make an explicit smoothing factor inFrameTimeDiagnosticsPlugin
optional?Or add a
new(max_history_length: usize)
method toFrameTimeDiagnosticsPlugin
that sets a reasonable defaultsmoothing_factor
? edit: This one seems like a no-brainer, doing it.Alternatives
It's really easy to roll your own
FrameTimeDiagnosticsPlugin
, but that might not be super interoperable with, for example, third party FPS overlays. Still, might be the right call.Testing
cargo run --example many_sprites
(modified to use a custommax_history_length
)Migration Guide
FrameTimeDiagnosticsPlugin
now contains two fields. UseFrameTimeDiagnosticsPlugin::default()
to match Bevy's previous behavior or, for example,FrameTimeDiagnosticsPlugin::new(60)
to configure it.