Skip to content

Add button benchmark#6854

Merged
lucasmerlin merged 4 commits intomasterfrom
lucas/add-button-benchmark
Apr 28, 2025
Merged

Add button benchmark#6854
lucasmerlin merged 4 commits intomasterfrom
lucas/add-button-benchmark

Conversation

@lucasmerlin
Copy link
Collaborator

@lucasmerlin lucasmerlin commented Apr 24, 2025

This helped me benchmark the atomic layout (#5830) changes.

I also realized that the label benchmark wasn't testing the painting, since the buttons at some point will be placed outside the screen_rect, meaning it won't be painted.

This fixes it by benching the label in a child ui.

The label &str benchmark went from 483 ns to 535 ns with these changes.

EDIT:

I fixed another benchmark problem, since the benchmark would show the same widget millions of times for a single frame, the WidgetRects hashmap would get huge, causing each iteration to slow down a bit more and causing the benchmark to have unreliable results.

With this the label &str benchmark went from 535ns to 298ns. Also the label format! benchmark now takes almost the same time (302 ns). Before, it was a lot slower since it reused the same Context which already had millions of widget ids.

I also realized that the label benchmark wasn't testing the painting, since the buttons at some point will be placed outside the screen_rect, meaning it won't be painted.

This fixes it by benching the label in a child ui.

The label &str benchmark went from 483 ns to 535 ns with these changes.
@github-actions
Copy link

Preview available at https://egui-pr-preview.github.io/pr/6854-lucasadd-button-benchmark
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

Comment on lines +63 to +67
|| ui.new_child(UiBuilder::new()),
|ui| {
ui.label("the quick brown fox jumps over the lazy dog");
},
BatchSize::LargeInput,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to explain why we create a child ui. The best way to explain it would be to test it (i.e. make sure there are more shapes after the call to ui.label then before it

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and below

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I explain it in the create_benchmark_ui doc comment

@lucasmerlin lucasmerlin force-pushed the lucas/add-button-benchmark branch from cb0fe47 to 7d37bc2 Compare April 25, 2025 14:02
@lucasmerlin lucasmerlin merged commit 7d185ac into master Apr 28, 2025
21 checks passed
@lucasmerlin lucasmerlin deleted the lucas/add-button-benchmark branch April 28, 2025 09:58
darkwater pushed a commit to darkwater/egui that referenced this pull request Aug 24, 2025
This helped me benchmark the atomic layout (emilk#5830) changes.

I also realized that the label benchmark wasn't testing the painting,
since the buttons at some point will be placed outside the screen_rect,
meaning it won't be painted.

This fixes it by benching the label in a child ui.

The `label &str` benchmark went from 483 ns to 535 ns with these
changes.

EDIT:

I fixed another benchmark problem, since the benchmark would show the
same widget millions of times for a single frame, the WidgetRects
hashmap would get huge, causing each iteration to slow down a bit more
and causing the benchmark to have unreliable results.

With this the `label &str` benchmark went from 535ns to 298ns. Also the
`label format!` benchmark now takes almost the same time (302 ns).
Before, it was a lot slower since it reused the same Context which
already had millions of widget ids.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exclude from changelog performance Lower CPU/GPU usage (optimize)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants