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.
After much deliberation and experimentation, I have decided that forking hecs is a better fit for Bevy's ECS needs. Legion is a top tier ECS by all measures, but hecs has a number of properties that make it desirable for our project:
System Functions: Its types are much more compatible with Bevy's "system functions". A recent legion refactor is incompatible with our system function implementation. Additionally, legion's lifetimes were already incompatible with system functions. We had to fork legion (and make it less safe) in order to make them work at all.
Compile Times / Code Complexity: hecs is much simpler and compiles much faster. On my machine legion (with all default features disabled to be fair) clean builds in ~12 seconds, whereas default hecs compiles in ~3. With equivalent "bevy system function" implementations (and serde enabled in both libs) hecs compiles in ~7 seconds whereas legion compiles in ~45.
Performance: default hecs is faster than legion according to
ecs_bench
. bevy's optimized hecs fork w/ system functions is way faster than legion (or any other rust ecs as far as I know). The "pos_vel" update benchmark results:Less Opinionated: hecs' simplicity allows us to take it in our own direction / makes me more comfortable forking it. it means we need to do more work (ex: serialization + multithreading + scheduling), but it also means we are more free to mold it into the best ecs for bevy.
Here are the details of the hecs fork:
world.get::<Component>(entity)
lookup now requires hashing, which by our benchmarks is about 5x slower than the previous array indexing implementation. Given that this is an uncommon pattern and the major benefits the new design yields, we consider this small corner-case performance cost worth it.Its worth pointing out that almost none of these changes were 100% my idea. In many ways bevy_ecs is a consolidation of my favorite ideas from Legion (boxed system traits + schedules + resources), Shipyard (system functions + using archetypes to store resources + queryable entities), and Hecs (core ECS implementation .. which is actually also inspired by Legion). If any of the developers of those projects ever read this, I want to give a huge thanks to all of you. I'm really standing on the shoulders of giants here.