-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use radsort for Transparent2d PhaseItem sorting #9882
Merged
Merged
Conversation
This file contains 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
rparrett
added
A-Rendering
Drawing game state to the screen
C-Performance
A change motivated by improving speed, memory usage or compile times
labels
Sep 21, 2023
Co-authored-by: Alice Cecile <[email protected]>
superdump
approved these changes
Sep 21, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine as-is. But a couple of comments anyway.
rparrett
changed the title
Use radsort for Transparent2d PhaseItems sorting
Use radsort for Transparent2d PhaseItem sorting
Sep 21, 2023
Co-authored-by: Robert Swain <[email protected]>
alice-i-cecile
approved these changes
Sep 21, 2023
43 tasks
rdrpenguin04
pushed a commit
to rdrpenguin04/bevy
that referenced
this pull request
Jan 9, 2024
# Objective Fix a performance regression in the "[bevy vs pixi](https://github.com/SUPERCILEX/bevy-vs-pixi)" benchmark. This benchmark seems to have a slightly pathological distribution of `z` values -- Sprites are spawned with a random `z` value with a child sprite at `f32::EPSILON` relative to the parent. See discussion here: bevyengine#8100 (comment) ## Solution Use `radsort` for sorting `Transparent2d` `PhaseItem`s. Use random `z` values in bevymark to stress the phase sort. Add an `--ordered-z` option to `bevymark` that uses the old behavior. ## Benchmarks mac m1 max | benchmark | fps before | fps after | diff | | - | - | - | - | | bevymark --waves 120 --per-wave 1000 --random-z | 42.16 | 47.06 | 🟩 +11.6% | | bevymark --waves 120 --per-wave 1000 | 52.50 | 52.29 | 🟥 -0.4% | | bevymark --waves 120 --per-wave 1000 --mode mesh2d --random-z | 9.64 | 10.24 | 🟩 +6.2% | | bevymark --waves 120 --per-wave 1000 --mode mesh2d | 15.83 | 15.59 | 🟥 -1.5% | | bevy-vs-pixi | 39.71 | 59.88 | 🟩 +50.1% | ## Discussion It's possible that `TransparentUi` should also change. We could probably use `slice::sort_unstable_by_key` with the current sort key though, as its items are always sorted and unique. I'd prefer to follow up later to look into that. Here's a survey of sorts used by other `PhaseItem`s #### slice::sort_by_key `Transparent2d`, `TransparentUi` #### radsort `Opaque3d`, `AlphaMask3d`, `Transparent3d`, `Opaque3dPrepass`, `AlphaMask3dPrepass`, `Shadow` I also tried `slice::sort_unstable_by_key` with a compound sort key including `Entity`, but it didn't seem as promising and I didn't test it as thoroughly. --------- Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Robert Swain <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-Rendering
Drawing game state to the screen
C-Performance
A change motivated by improving speed, memory usage or compile times
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
Fix a performance regression in the "bevy vs pixi" benchmark.
This benchmark seems to have a slightly pathological distribution of
z
values -- Sprites are spawned with a randomz
value with a child sprite atf32::EPSILON
relative to the parent.See discussion here: #8100 (comment)
Solution
Use
radsort
for sortingTransparent2d
PhaseItem
s.Use random
z
values in bevymark to stress the phase sort. Add an--ordered-z
option tobevymark
that uses the old behavior.Benchmarks
mac m1 max
Discussion
It's possible that
TransparentUi
should also change. We could probably useslice::sort_unstable_by_key
with the current sort key though, as its items are always sorted and unique. I'd prefer to follow up later to look into that.Here's a survey of sorts used by other
PhaseItem
sslice::sort_by_key
Transparent2d
,TransparentUi
radsort
Opaque3d
,AlphaMask3d
,Transparent3d
,Opaque3dPrepass
,AlphaMask3dPrepass
,Shadow
I also tried
slice::sort_unstable_by_key
with a compound sort key includingEntity
, but it didn't seem as promising and I didn't test it as thoroughly.