Hi,
The new BuildPipelineInterfaces is a lot neater than the old attribute way, and I do really like it. However, recently after upgrading to 5.6 I was investigating scene loading performance in the editor and came across this:
In this scene a lot of neighboring scenes are streamed in. The spikes (>200ms) come from BuildPipelineInterfaces.InitializeBuildMethods. For every scene that is loaded this is called again. This method scans all unitys & your assemblies and uses reflection to find the right build interfaces - meaning the larger our project gets the worse this will be.
This makes games with level streaming in editor really laggy and hard to play. Itâs sucks to have all of these well oiled systems working together to create a smooth streaming experience, but then only to have all that undermined because the build team didnât optimise their callback system.
The biggest problem is that InitializeBuildCallbacks is called for every scene while really it seems like it should only happen in the first scene. Iâve reported a bug (case nr 933800)
If I can go on a somewhat larger rant here though, this way of handling callbacks has always frustrated me. Take a look at profiles like these:
The marks indicate systems doing the same type of reflection over your code looking for attributes. This I believe is an important cause why unity performance degrades for larger projects. This attribute scanning happens every time you enter play mode and every time you recompile code. Actions users perform many many, upwards of hundreds, times a day (Relevant XKCD). It sucks more and more the larger projects get, and especially now that more of the engine is being moved to C# this wonât scale. In an ideal world these callbacks would be cached in the AssetDatabase and updated incrementally. Also having some kind of shared UnityReflectionManager that all the subsystems could talk to could help.
All in all, I really hope something can be done about BuildPipelineInterfaces urgently, and longer term it;d be really great if something was done about this way of handling these types callbacks generally.
Best regards,
Arthur