python-sc2 icon indicating copy to clipboard operation
python-sc2 copied to clipboard

Makes unit.tag be @cached_property

Open dysonreturns opened this issue 6 months ago • 0 comments

This commit is an optimization. I ran cProfiler on an example bot of sorts and noticed that unit.tag is one of the worst offenders. I made it a cached property instead and it cleared itself up.

This is due to heavy dictionary lookups in practice. Rasper has been manually caching tag in his framework for some time, using custom overrides and agrees this change is safe. So, nowhere in the library or in the wild do we manually change a unit's identifier once set.

I firmly believe this can go upstream.

Before:
before

After:
after

dysonreturns avatar Jun 26 '25 13:06 dysonreturns