[Merged by Bors] - [ecs] Improve Commands performance#2332
[Merged by Bors] - [ecs] Improve Commands performance#2332NathanSWard wants to merge 25 commits intobevyengine:mainfrom
Commands performance#2332Conversation
|
Here is a list of the minimal performance tests I created. |
|
I have a feeling that since this is a pretty specialized structure I should probably just move it into |
|
Hmm, should we maybe pull the commands benchmark into a separate PR and merge it earlier? It's far less controversial than the unsafe anystack impl, and reducing the scope of PR s with unsafe is usually a good thing |
DJMcNab
left a comment
There was a problem hiding this comment.
I really like the idea of using an fn here. Apart from the alignment issue you have pointed out, this looks good.
6a179d1 to
5d6db0f
Compare
DJMcNab
left a comment
There was a problem hiding this comment.
I haven't checked over the tests in detail, but if this passes miri, I can believe it's good to go.
I'll go ahead and run miri with this sometime today/tomorrow and report back the results. |
DJMcNab
left a comment
There was a problem hiding this comment.
Looks good, a few docs thoughts
51b2fe0 to
0d75c6b
Compare
|
Here are the most recent benchmarks (taken from #2334). |
543522c to
2fb8a5a
Compare
|
As @mockersf suggested I created a benchmark that utilized |
ae297f1 to
2a614b8
Compare
|
benchmarks for the most recent version. (with special casing for 0 sized commands and ensuring the vector isn't null). |
9dbe32f to
a9be103
Compare
|
@cart this should be good to go now :) |
|
bors r+ |
# Objective
- Currently `Commands` are quite slow due to the need to allocate for each command and wrap it in a `Box<dyn Command>`.
- For example:
```rust
fn my_system(mut cmds: Commands) {
cmds.spawn().insert(42).insert(3.14);
}
```
will have 3 separate `Box<dyn Command>` that need to be allocated and ran.
## Solution
- Utilize a specialized data structure keyed `CommandQueueInner`.
- The purpose of `CommandQueueInner` is to hold a collection of commands in contiguous memory.
- This allows us to store each `Command` type contiguously in memory and quickly iterate through them and apply the `Command::write` trait function to each element.
Commands performanceCommands performance
# Objective
- Currently `Commands` are quite slow due to the need to allocate for each command and wrap it in a `Box<dyn Command>`.
- For example:
```rust
fn my_system(mut cmds: Commands) {
cmds.spawn().insert(42).insert(3.14);
}
```
will have 3 separate `Box<dyn Command>` that need to be allocated and ran.
## Solution
- Utilize a specialized data structure keyed `CommandQueueInner`.
- The purpose of `CommandQueueInner` is to hold a collection of commands in contiguous memory.
- This allows us to store each `Command` type contiguously in memory and quickly iterate through them and apply the `Command::write` trait function to each element.
Objective
Commandsare quite slow due to the need to allocate for each command and wrap it in aBox<dyn Command>.will have 3 separate
Box<dyn Command>that need to be allocated and ran.Solution
CommandQueueInner.CommandQueueInneris to hold a collection of commands in contiguous memory.Commandtype contiguously in memory and quickly iterate through them and apply theCommand::writetrait function to each element.