[core] Optimize main loop.