Moved things that depend on container size change out of renderLoop() to improve performance.