bevy/crates/bevy_ecs/src
JoJoJet 5d912a2f35 Speed up CommandQueue by storing commands more densely (#6391)
# Objective

* Speed up inserting and applying commands. 
* Halve the stack size of `CommandQueue` to 24 bytes.
* Require fewer allocations.

## Solution

Store commands and metadata densely within the same buffer. Each command takes up 1 `usize` of metadata, plus the bytes to store the command itself. Zero-sized types take up no space except for the metadata.

# Benchmarks

All of the benchmarks related to commands.

| Bench                                  | Time      |  % Change         |    p-value |
|----------------------------------------|-----------|--------------|-----------------|
| empty_commands/0_entities              | 4.7780 ns | -18.381% | 0.00  |
| spawn_commands/2000_entities           | 233.11 us | -0.9961%     | 0.00  |
| spawn_commands/4000_entities           | 448.38 us | -3.1466%     | 0.00  |
| spawn_commands/6000_entities           | 693.12 us | -0.3978%     | _0.52_ |
| spawn_commands/8000_entities           | 889.48 us | -2.8802%     | 0.00  |
| insert_commands/insert                 | 609.95 us | -4.8604%     | 0.00  |
| insert_commands/insert_batch           | 355.54 us | -2.8165%     |  0.00 |
| fake_commands/2000_commands            | 4.8018 us | **-17.802%** | 0.00  |
| fake_commands/4000_commands            | 9.5969 us | **-17.337%** | 0.00  |
| fake_commands/6000_commands            | 14.421 us | **-18.454%** | 0.00  |
| fake_commands/8000_commands            | 19.192 us | **-18.261%** | 0.00 |
| sized_commands_0_bytes/2000_commands   | 4.0593 us | -4.7145%     |  0.00 |
| sized_commands_0_bytes/4000_commands   | 8.1541 us | -4.9470%     |  0.00  |
| sized_commands_0_bytes/6000_commands   | 12.806 us | -12.017%     | 0.00 |
| sized_commands_0_bytes/8000_commands   | 17.096 us | -14.070% |  0.00 |
| sized_commands_12_bytes/2000_commands  | 5.3425 us | **-27.632%** | 0.00 |
| sized_commands_12_bytes/4000_commands  | 10.283 us | **-31.158%** |  0.00  |
| sized_commands_12_bytes/6000_commands  | 15.339 us | **-31.418%** |  0.00 |
| sized_commands_12_bytes/8000_commands  | 20.206 us | **-33.133%** |  0.00 |
| sized_commands_512_bytes/2000_commands | 99.118 us | -9.9655%     |  0.00  |
| sized_commands_512_bytes/4000_commands | 201.96 us | -8.8235%     |  0.00 |
| sized_commands_512_bytes/6000_commands | 300.95 us | -9.2344%     |  0.00  |
| sized_commands_512_bytes/8000_commands | 404.69 us | -8.4578%     |  0.00  |
2023-01-28 01:15:51 +00:00
..
entity Make EntityRef::new unsafe (#7222) 2023-01-16 22:10:51 +00:00
query Basic adaptive batching for parallel query iteration (#4777) 2023-01-20 08:47:20 +00:00
schedule Fix minor typos in code and docs (#7378) 2023-01-27 12:12:53 +00:00
schedule_v3 Fix minor typos in code and docs (#7378) 2023-01-27 12:12:53 +00:00
storage Add World::clear_resources & World::clear_all (#3212) 2023-01-17 04:20:42 +00:00
system Speed up CommandQueue by storing commands more densely (#6391) 2023-01-28 01:15:51 +00:00
world Allow returning a value from EntityMut::world_scope (#7385) 2023-01-27 19:42:10 +00:00
archetype.rs Fix minor typos in code and docs (#7378) 2023-01-27 12:12:53 +00:00
bundle.rs Fix beta clippy lints (#7154) 2023-01-11 09:51:22 +00:00
change_detection.rs Add a method for converting MutUntyped -> Mut<T> (#7113) 2023-01-11 17:47:54 +00:00
component.rs Added resource_id and changed init_resource and init_non_send_resource to return ComponentId (#7284) 2023-01-20 19:08:04 +00:00
event.rs Rework manual event iterator so we can actually name the type (#5735) 2022-12-25 00:39:27 +00:00
lib.rs Fix minor typos in code and docs (#7378) 2023-01-27 12:12:53 +00:00
reflect.rs add UnsafeWorldCell abstraction (#6404) 2023-01-27 00:12:13 +00:00