Editor vs code performance

Hi, Im new to Unity but came from c# backend web development. I started to google some info about best practices related to performance and was surprised that there is much less info than in my old work field, or at least its harder to find. Almost everything leads to this forum and there is little info outside of it which is very surprising to me. At the end I decided to ask a questions here.

Is there a preformance difference between putting object in a scene in editor, creating one via constructor and instantiating a prefab?

To my undestanding instantianing a prefab is equivalent of reflection Activator and it has some overhead in terms of dynamic lookups for types, constructors etc.
Creating default gameobject via constructor is probably almost the same bc you pass types of components.
So I’m very curious in what exactly happens with referencing through an editor. Are dependancies somehow resolve in compile time?

Basically these can be reduced to: is there a difference between code scene management and editor scene management in terms of performance. Are there some benchmarks for it?

PS: I think I need to specify that I dont have a specific project even in mind and just try to learn the engine for now

There may not be much sources about general optimization for Unity out there, but normally you should not be too concerned about that. Mostly performance optimizations are done very late in the project and using the Unity Profiler to identify bottlenecks. At least this is the common approach, but I understand your question and it would never be wrong to have some best practices to consider right from the start.

As far as I know, all game objects part of the scene get loaded when the scene is loaded. So having more game objects would probably increase scene load up times, but I do not know whether Unity has some optimizations when loading a scene having a single prefab instantiated thousands of times.
You should not create game objects with a direct constructor call, instead providing the prefab game object to:

You can optimize game object instantiation using game object pools:

But be aware that you are in charge for resetting the game objects properly when returning/reusing them to/from the pool. So this usually introduces bugs. But instantiating many game objects at once in a single frame causes FPS drops in Unity, so pooling may solve this. But you can also distribute game object instantiation over multiple frames when possible to avoid pooling complexity.

If you really strive for high performance you should take a look at Entity Component System in conjunction with Burst compilation. But this is a much more difficult path than simply using classic game objects.

In game dev, getting something working in the first place is most important. No point in optimising a mechanic that doesn’t work in the first place. No point optimising visuals you don’t have. No point in even optimising something that’s not a performance concern to begin with.

If you’re new, it’s just more important to learn how to use the engine, and learn how to achieve the specific goals you have in mind. If a performance issue arises, then you can find a solution for it; and someone probably already has at some point, too.

Have fun! Worrying yourself about optimisation at this stage is boring and will kill your enthusiasm.