-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
Speedup TryGet #232
base: master
Are you sure you want to change the base?
Speedup TryGet #232
Conversation
Code done by ElectroJr not me, I just PRd it.
internal bool TryIndex<T>(out int i) | ||
{ | ||
var id = Component<T>.ComponentType.Id; | ||
Debug.Assert(id != -1, $"Index is out of bounds, component {typeof(T)} with id {id} does not exist in this chunk."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assert text should probably be updated and I don't think its actually correct, I'm not sure if -1 is even possible? I think I initially just pilfered part of the asset from Chunk.Index<T>()
and never really updated the text.
return false; | ||
} | ||
|
||
component = archetype.Get<T>(ref slot); | ||
ref var chunk = ref slot.Archetype.GetChunk(slot.Slot.ChunkIndex); | ||
Debug.Assert(compIndex != -1 && compIndex < chunk.Components.Length, $"Index is out of bounds, component {typeof(T)} with id {compIndex} does not exist in this chunk."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assert message was also pilfered from elsewhere, and the "does not exist in this chunk" should probably be updated as it is not in Chunk
method anymore
var entitySlot = EntityInfo.GetEntitySlot(entity.Id); | ||
var slot = entitySlot.Slot; | ||
var archetype = entitySlot.Archetype; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC these changes were from an older arch version and aren't really required anymore. I.e., previously it was getting the entity slot twice using
var slot = EntityInfo.GetSlot(entity.Id);
var archetype = EntityInfo.GetArchetype(entity.Id);
but the current version doesn't seem to do that anymore.
if (!(exists = archetype.Has<T>())) | ||
if (!(exists = slot.Archetype.Has<T>())) | ||
{ | ||
return ref Unsafe.NullRef<T>(); | ||
} | ||
|
||
return ref archetype.Get<T>(ref slot); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can probably also be changed to use TryGetIndex instead of Has<T>
& Get<T>
. IIRC I just didn't bother update it for the SS14 benchmarks because they weren't using this method
Code done by @ElectroJr not me, I just PRd it.
Without the GetChunk change:
With GetChunk change:
Left is master, right is after changes (the non-generic TryGet was just my system being weird, after multiple runs it was equivalent).