Commit 11c544c
committed
Remove redundant table and sparse set component IDs from Archetype (#4927)
# Objective
Archetype is a deceptively large type in memory. It stores metadata about which components are in which storage in multiple locations, which is only used when creating new Archetypes while moving entities.
## Solution
Remove the redundant `Box<[ComponentId]>`s and iterate over the sparse set of component metadata instead. Reduces Archetype's size by 4 usizes (32 bytes on 64-bit systems), as well as the additional allocations for holding these slices.
It'd seem like there's a downside that the origin archetype has it's component metadata iterated over twice when creating a new archetype, but this change also removes the extra `Vec<ArchetypeComponentId>` allocations when creating a new archetype which may amortize out to a net gain here. This change likely negatively impacts creating new archetypes with a large number of components, but that's a cost mitigated by the fact that these archetypal relationships are cached in Edges and is incurred only once for each edge created.
## Additional Context
There are several other in-flight PRs that shrink Archetype:
- #4800 merges the entities and rows Vecs together (shaves off 24 bytes per archetype)
- #4809 removes unique_components and moves it to it's own dedicated storage (shaves off 72 bytes per archetype)
---
## Changelog
Changed: `Archetype::table_components` and `Archetype::sparse_set_components` return iterators instead of slices. `Archetype::new` requires iterators instead of parallel slices/vecs.
## Migration Guide
Do I still need to do this? I really hope people were not relying on the public facing APIs changed here.1 parent 51aab03 commit 11c544c
File tree
3 files changed
+39
-48
lines changed- crates/bevy_ecs/src
- world
3 files changed
+39
-48
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
187 | 185 | | |
188 | 186 | | |
189 | 187 | | |
190 | 188 | | |
191 | 189 | | |
192 | 190 | | |
193 | 191 | | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
| 192 | + | |
| 193 | + | |
198 | 194 | | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
204 | 199 | | |
205 | | - | |
| 200 | + | |
206 | 201 | | |
207 | 202 | | |
208 | 203 | | |
209 | 204 | | |
210 | 205 | | |
211 | 206 | | |
212 | 207 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
| 208 | + | |
217 | 209 | | |
218 | | - | |
| 210 | + | |
219 | 211 | | |
220 | 212 | | |
221 | 213 | | |
| |||
225 | 217 | | |
226 | 218 | | |
227 | 219 | | |
228 | | - | |
229 | 220 | | |
230 | | - | |
231 | | - | |
| 221 | + | |
232 | 222 | | |
233 | 223 | | |
234 | 224 | | |
| |||
249 | 239 | | |
250 | 240 | | |
251 | 241 | | |
252 | | - | |
253 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
254 | 247 | | |
255 | 248 | | |
256 | 249 | | |
257 | | - | |
258 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
259 | 255 | | |
260 | 256 | | |
261 | 257 | | |
| |||
484 | 480 | | |
485 | 481 | | |
486 | 482 | | |
487 | | - | |
488 | | - | |
489 | 483 | | |
490 | | - | |
491 | | - | |
| 484 | + | |
| 485 | + | |
492 | 486 | | |
493 | 487 | | |
494 | 488 | | |
495 | 489 | | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | 490 | | |
502 | 491 | | |
503 | 492 | | |
504 | 493 | | |
505 | 494 | | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
512 | 503 | | |
513 | 504 | | |
514 | 505 | | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
519 | 510 | | |
520 | 511 | | |
521 | 512 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
461 | 461 | | |
462 | 462 | | |
463 | 463 | | |
464 | | - | |
| 464 | + | |
465 | 465 | | |
466 | 466 | | |
467 | 467 | | |
| |||
477 | 477 | | |
478 | 478 | | |
479 | 479 | | |
480 | | - | |
| 480 | + | |
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
508 | | - | |
| 508 | + | |
509 | 509 | | |
510 | 510 | | |
511 | 511 | | |
| |||
843 | 843 | | |
844 | 844 | | |
845 | 845 | | |
846 | | - | |
847 | | - | |
| 846 | + | |
| 847 | + | |
848 | 848 | | |
849 | 849 | | |
850 | 850 | | |
| |||
0 commit comments