How can I optimize meshes for over 20,000 cubes?

The simplest example is here - https://playground.babylonjs.com/#3A2PUF#2
It renders the scene only when pointerDown.
Another example with RollingAverage - Babylon.js Playground
But without knowing your specific application it is difficult to give you the exact answer.
This subject has a lot of discussions, so I would suggest you to search first; and, then, to find the best method for your case.
Here just a couple of links - there are dozens of them:
What's the difference between engine.getDeltaTime and scene.getAnimationRatio? - Questions - Babylon.js
Decoupling Frame rate from movement speed issues - Questions - Babylon.js
Which Best Method for Mesh Rendering (Updated Every Frame) - Questions - Babylon.js
From old Forum - Controlling the render loop - Questions & Answers - HTML5 Game Devs Forum

2 Likes