If you’ve been following my recent posts, you know that I’m working on a procedural level generator for the Neil Rajah levels. For now it’s just a ground generator. I’m using Artemis, which is an entity-component system. The code for creating the ground in Artemis started out pretty simple – for each tile, I create a new entity which has components for the physics and spatial / renderable information. My first performance fix was to ensure that the Sprite objects don’t get invalidated on each frame, which forced them to recalculate their vertices. This fixed an issue which caused the game to run at 15fps on my phone. My next optimization was physics related – instead of one box2d object per tile, I’m using one object (basically a large rectangle) per ground section. Both of these helped with running the game, but I still had a problem each time I started a level – the level creation took a long time, so the game stalled for a while before you could play it. I’ve spent some time looking into this, and trying to figure out what I can do to fix it.