Search Unity

Assembly Definition increasing compile time a lot, not decreasing

Discussion in 'Editor & General Support' started by mmortall, Feb 19, 2018.

  1. mmortall

    mmortall

    Joined:
    Dec 28, 2010
    Posts:
    89
    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):
    1. Game.dll (Assembly of my game code) around 30 kb
    2. Assembly-CSharp.dll
    3. Assembly-CSharp-firstpass.dll
    4. Assembly-CSharp-Editor.dll
    5. Assembly-CSharp-Editor-firstpass.dll
    6. 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?
     
    cxode likes this.
  2. mmortall

    mmortall

    Joined:
    Dec 28, 2010
    Posts:
    89
    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?
     
    Neiist likes this.
  3. Shrubokrant

    Shrubokrant

    Joined:
    Oct 2, 2016
    Posts:
    80
    I have the same feeling, on my project, our compilation time doubled since we started to use custom assembly files
     
    Neiist likes this.
  4. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    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.
     
    ksf000 likes this.
  5. Gerold_Meisinger

    Gerold_Meisinger

    Joined:
    Sep 8, 2015
    Posts:
    93
  6. mmortall

    mmortall

    Joined:
    Dec 28, 2010
    Posts:
    89
    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.
     
    wlwl2 likes this.