nadako / Ash-Haxe

Port of Ash entity framework to Haxe
Other
131 stars 37 forks source link

Faster component adding #27

Closed scriptorum closed 9 years ago

scriptorum commented 9 years ago

My application uses Flaxen which can have a significant number of components per entity. This incurs a large number of calls to ComponentMatchingFamily.addIfMatch, especially when creating a bunch of entities at the same time. This profiles poorly mainly due to the custom ClassMap.keys implementation.

I've reworked that class to use a separate StringMap of class names to classes, which lets me replace the ClassMap.keys iterator with a simple call to keyMap.iterator. This runs much faster, at least on Flash. I have not tested this on other targets.

nadako commented 9 years ago

Thanks. I still think we could get move that Type.getClassName to compile-time, but I probably won't have time to work on it, so I'll just merge this.

scriptorum commented 9 years ago

Heh, I understand. I'd love to know how one can determine Type.getClassName() at compile-time. Macro, I suppose.

loudoweb commented 9 years ago

@scriptorum can you make a quick test on other targets if there is also a benefit? Thanks.

scriptorum commented 9 years ago

@loudoweb No problem. So the answer is yes, there was a speed improvement for each platform I tested. I repeatedly executing a loop resulting in at least 1500 entity adds with 10 components added to each, and timed the loop duration in seconds.

Platform Before After
Mac 1.8 1.1
Flash 5.3 2.5
Neko 11.5 5.9
loudoweb commented 9 years ago

Awesome. Thank you!