nadako / Ash-Haxe

Port of Ash entity framework to Haxe

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ClassMap.keys() slows down over time

scriptorum opened this issue · comments

I'm pulling my hair out over this one. Has anyone experienced slow downs in ClassMap.keys() on CPP targets? I have a level with about 180 entities in it. When I reload the level, I remove all level-based entities and then recreate them. This process takes longer and longer each time. For example, the first time it takes ~56ms, and the 20th time it takes ~5000ms. The accelerating nature of the time is disconcerting.

I've tracked the issue to ClassMap.keys(), or more specifically its use of StringMap.keys(). It is called from ComponentMatchingFamily.addIfMatch(). The Haxe profiler confirms that on the 20th reload 93% of the time is taken up by calls to StringMap.keys(). It's not entirely consistent, as most calls take <1ms, and then suddenly there will be a spike. There are never more than 3 keys in the map. The profiler indicates the time in StringMap.keys is coming from its use of GC::new.

It sounds like garbage collection is kicking in periodically (and more frequently than 30 seconds), but I can't figure out why the time cost is accelerating. I've confirmed that I have 180 entities each time, and each entity has about 6 components. There is no slowdown on the Flash target. Does anyone have any thoughts on this, or what I can do to track it further?

It's possible this might just be a symptom of a memory leak with my app. I'm rapidly adding a removing a lot of components from entities, and that causes keys() to get called, which creates an Array under the hood to store the keys to be returned. This triggers the recycler. I'll reopen this issue if I can put together a simple test app that illustrates the issue.