Skip to content

refactor: optimize is_detector by using raw int set - #250

Closed
SamOgon-one wants to merge 2 commits into
BurnySc2:developfrom
SamOgon-one:refactor/detector-rewrite
Closed

SamOgon-one wants to merge 2 commits into
BurnySc2:developfrom
SamOgon-one:refactor/detector-rewrite

Conversation

@SamOgon-one

Copy link
Copy Markdown
Contributor

Summary

Optimizes unit.is_detector by replacing UnitTypeId enum lookups with a raw integer frozenset[int] check, reordering boolean conditions for faster short-circuiting, and using a standard @property.

  • Eliminates enum conversion overhead: Directly checks the raw Protobuf integer against IS_DETECTOR_TYPES instead of converting it into a UnitTypeId enum via self.type_id.

  • Faster on fresh units: In python-sc2, Unit instances are recreated every frame, and is_detector is typically queried only zero or one time per unit. @cached_property is way slower on the first call on fresh units due to writing into unit.__dict__.

@SamOgon-one SamOgon-one closed this Nov 6, 2026
@SamOgon-one
SamOgon-one deleted the refactor/detector-rewrite branch November 6, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant