Can I reduce the lag, while I create 1000 cubes

So I created about 1000 cubes with the Instantiate() method. This is happenig in a for loop. When I start the program it works totally fine except that it is lagging a lot. If I increase the number even more it takes a long time to load and is nearly crashing my unity editor. Do you have any idea how i can load the Cubes without lagging? Or any other ideas how I can optimize that?

Hello.

You should lern to use Ienumerators (Corutines)

So you can instantiate a few number of Cubes (25-50 for example) each frame (and not all of them in the same frame as you are doing now) to reduce lag.

There are so many tutorials about corutines, go investigate,

Good luck!

Please do NOT use coroutines for this task. I know, it sounds like the right solution but the name may be misleading, Why? Coroutines run on the same thread that launches them and not on a separate one. A̶n̶d̶ ̶s̶i̶n̶c̶e̶ ̶p̶e̶r̶f̶o̶r̶m̶a̶n̶c̶e̶ ̶i̶n̶ ̶t̶h̶i̶s̶ ̶c̶a̶s̶e̶ ̶i̶s̶ ̶v̶e̶r̶y̶ ̶m̶u̶c̶h̶ ̶r̶e̶l̶a̶t̶e̶d̶ ̶t̶o̶ ̶r̶e̶n̶d̶e̶r̶i̶n̶g̶ ̶o̶f̶ ̶t̶h̶e̶ ̶o̶b̶j̶e̶c̶t̶s̶ ̶m̶o̶r̶e̶ ̶t̶h̶a̶n̶ ̶t̶h̶e̶i̶r̶ ̶i̶n̶s̶t̶a̶n̶t̶i̶a̶t̶i̶o̶n̶,̶ ̶t̶h̶r̶e̶a̶d̶s̶ ̶a̶r̶e̶ ̶n̶o̶t̶ ̶e̶v̶e̶n̶ ̶t̶h̶e̶ ̶m̶a̶i̶n̶ ̶t̶h̶i̶n̶g̶ ̶y̶o̶u̶ ̶s̶h̶o̶u̶l̶d̶ ̶c̶a̶r̶e̶ ̶a̶b̶o̶u̶t̶.̶

In my opinion, t̶w̶o̶ ̶a̶p̶p̶r̶o̶a̶c̶h̶e̶s̶ ̶y̶o̶u̶ ̶s̶h̶o̶u̶l̶d̶ ̶c̶o̶m̶b̶i̶n̶e̶ ̶a̶r̶e̶ what you should do is to:

  1. Use unity Job system
  2. V̶o̶x̶e̶l̶s̶

As @Bonfire-Boy suggested the issue is more about instantiation of the objects rather than their rendering.
If you see your performances will stay low even after optimizing the instantiation, that’s very likely because there is too much to render: if that’s the case, I would suggest to check Voxels.
These are advanced topics but there’s plenty of documentation and tutorials out there, so I’m more than confident that if you really want to achieve great results, you can do that! Just be patient to learn and comprehend all that stuff: it will be VERY rewarding, I promise.