-
-
Notifications
You must be signed in to change notification settings - Fork 137
Optimize adding a single component type to an entity, add benchmarks #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
As a comparison, these are the same benchmarks without the World.Add or Archetype changes, using only the changes in Chunk.cs:
|
Looks great! :) E.g. i just realize that there other aspects which could make use of a similar mechanic ^^ |
Done in this commit New benchmarks: BenchmarkDotNet=v0.13.2, OS=Windows 10 (10.0.19045.2846) Old:
New:
|
Also makes Chunk.Has and Chunk.CopyComponents faster.
Heavily inspired by flecs. See https://github.com/SanderMertens/flecs/blob/master/docs/Relationships.md#id-ranges and https://ajmmertens.medium.com/building-an-ecs-2-archetypes-and-vectorization-fe21690805f9
When the component type id is below 256 an array is used, otherwise a dictionary is used, similar to flecs.
The array is only allocated after the first time that an archetype is modified, and only to the size that it needs to fit the component type id with each usage.
A preprocessor directive is used in case CollectionsMarshal does not exist (pre .NET 5)
BenchmarkDotNet=v0.13.2, OS=Windows 10 (10.0.19045.2846)
AMD Ryzen 9 7900X, 1 CPU, 24 logical and 12 physical cores
.NET SDK=7.0.203
[Host] : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
DefaultJob : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
Old:
New: