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
Reuse TargetTypes collection in FrozenActor.RefreshState. #14917
Reuse TargetTypes collection in FrozenActor.RefreshState. #14917
Conversation
@@ -101,7 +101,8 @@ public FrozenActor(Actor actor, PPos[] footprint, Player viewer, bool startsReve | |||
public void RefreshState() | |||
{ | |||
Owner = actor.Owner; | |||
TargetTypes = actor.GetEnabledTargetTypes().ToHashSet(); | |||
TargetTypes.Clear(); |
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.
Can we include a // PERF:
comment here?
Definitely a noticeable improvement, at least going by perf.log. On bleed, 52 entries in first 2000 ticks on shellmap, many of them with 3-7 ms. |
dc5cfd0
to
73081f0
Compare
|
||
// PERF: Reuse collection to avoid allocations. | ||
TargetTypes.Clear(); | ||
TargetTypes.UnionWith(actor.GetEnabledTargetTypes()); |
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.
@RoosterDragon TargetTypes seems like a great candidate for load-time bitsetification.
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.
Interesting class. Is the idea you specify Bits<SomeMarkerStruct> TargetTypes
in multiple places and it automatically converts everything as it's loaded?
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.
Correct.
This is called a lot, and saves us reallocating a new hash set each time. Hopefully helps with #14905.