Use a unstable sort to sort component ids in bevy_ecs
#13789
Merged
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
While writing code for the
bevy_ecs
I noticed we were using a unnecessarily stable sort to sort component idsSolution
Testing
I ran
cargo test -p bevy_ecs
. Everything else I leave to CI.Profiling
I measured about a 1% speed increase when spawning entities directly into a world. Since the difference is so small (and might just be noise) I didn't bother to figure out which of change if any made the biggest difference.
Tracy data
Yellow is this PR. Red is the commit I branched from.Methodology
I created a system that spawn a 1000 entities each with the same 30 components each frame, and then I measured it's run time. The unusually high number of components was chosen because the standard library [will use a insertion sort for slices under 20 elements](https://github.com/rust-lang/rust/blob/0de24a5177b1d49d6304f76f3ab159faaec134f9/library/core/src/slice/sort.rs#L1048-L1049). This holds for both stable and unstable sorts.