Assembly Definition increasing compile time a lot, not decreasing

I am desperate. I’ve spent a whole day to migrate my project into Assembly Definition, but in result I get +5 sec compilation time than before.

I have around 20 .asmdef files. Around 16 for Plugins. One for Editor folder. Three for my game code.

When I change some game related file, only one custom dll are recompiled + some Unity related (according to file modification time in \Library\ScriptAssemblies):

  • Game.dll (Assembly of my game code) around 30 kb

  • Assembly-CSharp.dll

  • Assembly-CSharp-firstpass.dll

  • Assembly-CSharp-Editor.dll

  • Assembly-CSharp-Editor-firstpass.dll

  • Assembly-UnityScript-firstpass.dll

The overall sizes of assemblies is 5 times smaller than without asmdef files, so it really compiles less code. But the time not decreasing and even increases. Why?
Could anyone help me, please?

1 Like

So during my investigation, I’ve found out that even if you have an assembly file in your directory, code is still recompiled even if nothing changed. It is like I still have old compiler running in parallel with Assembly Definition

here the screen of my current test setup:

When I change test script it takes about 17 sec to recompile. If I remove all stuff in DLLPlugin and DLL Editor folder it takes 4 sec to recompile. This is a bug?

1 Like

I have the same feeling, on my project, our compilation time doubled since we started to use custom assembly files

1 Like

As per the docs, you should either use custom assemblies for everything, or nothing at all.
If you have something that is not in a custom assembly, it will be recompiled when any of your custom assemblies recompile. The reason being that non-custom assemblies have references to the custom assemblies (they are dependent).

To actually see any improvement, you need everything in your project using asmdef files.
If you have any of those Assembly-*.dll files, it means something is still not in a custom assembly.

In your case, when you change anything from your Game.dll, all those other Assembly-*.dll files are re-generated, so you’ll really see an increase in compilation time.

1 Like

Also see https://forum.unity.com/threads/unity-assembly-definition-files-slower-not-faster-how-to-compile-faster.511199

I’ve solved my issue. Thanks to the Gerold_Meisinger.
My problem was related to very long reload assemblies phase (around 13 sec) because there were lots of scripts with InitializeOnLoad doing some stuff in static constructors.
I still have Assembly-CSharp-firstpass.dll compilation around 1 sec but it is ok.

1 Like