How to optimize instanced meshes?

I am making a game where the world is procedurally generated with instanced static meshes but at some point I get over a million instances and the computer starts to lag which is a big problem considering the fact that the level is still really small. Is there anything I can change to optimize the game so that I can spawn a lot more instances without lag?

check hism

and see how 4.22 works with automatic instancing through “Mesh Drawing Pipeline Refactor”