Irrelon / ige

The Isogenic Game Engine
524 stars 139 forks source link

IGE-ES6 - Default behavior of _resizeEvent on IgeObject causes performance hit #468

Open beyond-code-github opened 5 years ago

beyond-code-github commented 5 years ago

By default every IgeObject gets an implementation of _resizeEvent that loops each child entity and calls their _resizeEvents in turn: https://github.com/Irrelon/ige/blob/cd4f470e828bc0f960b1023b515cde398ad9e188/engine/core/IgeObject.js#L1663

For a basic Isometric tile game with hundreds of entities belonging to a tilemap, this causes a significant lag each tick as we iterate every child but then take no action as nothing needs to respond to these events other than the scene, viewport etc which already have their own overrides for _resizeEvent anyways.

In my fork, I've simply commented out this entire method which has improved performance with no side effects but as I have a limited use-case I was wondering what a better solution to this might be before I sent a PR that might break things for others. Thanks!

beyond-code-github commented 1 year ago

Hello @Irrelon, I've re-opened this as the issue has returned in the new branch.

The issue is with adding entities to a tilemap in bulk. For each call to mount() on the parent, we iterate all the children and call their _resizeEvent() method, which ends up in the method being invoked n! (factorial) times.

I have a custom tilemap class so I've worked around this by overriding the _resizeEvent method to be a no-op. I do wonder if it's worth changing the default behaviour though as this could catch people out.

Irrelon commented 1 year ago

Hmm, yeah that does not sound good!! Can you share your usage snippet here so I can understand the flow?