Skip to content
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

Improve sprite ordering speed #3554

Closed
wants to merge 2 commits into from

Conversation

mockersf
Copy link
Member

@mockersf mockersf commented Jan 5, 2022

Objective

  • Sprite z ordering can be slow with many sprites

Solution

  • use partial_cmp instead of cmp through FloatOrd
  • use sort_unstable_by instead of sort_by

results on my laptop:

fps bevymark -- 25000 40 many_sprites
base 9.84 33.75
partial_cmp 10.44 44.60
sort_unstable_by 10.27 59.96
both 10.59 66.03
the screenshots!

base

many_sprites stable-cmp bevymark stable-cmp

partial_cmp

many_sprites stable-partial_cmp bevymark stable-partial_cmp

sort_unstable_by

many_sprites unstable-cmp bevymark unstable-cmp

both

many_sprites unstable-partial_cmp bevymark unstable-partial_cmp

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Jan 5, 2022
@mockersf mockersf added A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times and removed S-Needs-Triage This issue needs to be labelled labels Jan 5, 2022
Copy link
Contributor

@Davier Davier left a comment

Choose a reason for hiding this comment

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

I also find that using sort_unstable_by improves performance.
The render items are sorted again in sort_phase_system, but I think that should not become an unstable sort to avoid breaking batches.
The change means that sprites with a depth of NaN may be reordered differently in sort_phase_system, but that's fine by me.

@mockersf

This comment has been minimized.

@mockersf mockersf force-pushed the improve-sprite-ordering branch 3 times, most recently from a506153 to ce183ca Compare January 5, 2022 16:48
Copy link
Contributor

@inodentry inodentry left a comment

Choose a reason for hiding this comment

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

The logic with the index indirection seems incorrect.

crates/bevy_sprite/src/render/mod.rs Outdated Show resolved Hide resolved
crates/bevy_sprite/src/render/mod.rs Outdated Show resolved Hide resolved
@mockersf mockersf force-pushed the improve-sprite-ordering branch 2 times, most recently from d7a5c75 to 7095163 Compare January 5, 2022 17:40
@mockersf
Copy link
Member Author

mockersf commented Jan 5, 2022

turns out keeping a smaller index is slower when done without a bug, I removed it

@mockersf
Copy link
Member Author

mockersf commented Jan 7, 2022

this will change quite a bit with / is already part of #3460

@mockersf mockersf closed this Jan 7, 2022
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants