Search Unity

Unity Package Manager (re)compilation

Discussion in 'Package Manager' started by Alterego-Games, Sep 13, 2021.

  1. Alterego-Games

    Alterego-Games

    Joined:
    Jul 13, 2015
    Posts:
    354
    Hi all,

    Our team has been creating a tool framework for our projects. Each tool is independant and works plug&play. Each of the tools are exported to a scoped registry and importable as package through the Unity Packages manager, exactly in the same way how Unity's own packages are installable.

    I wonder, if the scripts in these (and Unity's packages) get recompiled everytime there is a change in a script, or if it only compiles once when getting imported. (I hope it is the latter!).
     
  2. Alterego-Games

    Alterego-Games

    Joined:
    Jul 13, 2015
    Posts:
    354
    So to try to get an answer on this, I created a test scenario.

    Test Case
    I added a script in the Assets folder that debugs the compilation time. Each time when the Editor starts/ends compilation.
    I than created an empty testscript which I edited each time, to start the recompilation. (I also tried with CompilationPipeline.RequestScriptCompilation(), but that yielded way different results, so I went with "normal Unity use".
    First I tried it 5 times, with no Packages, than with 24 of our own packages imported through the Package Manager. All of those 24 packages only have assets in the Package folder, no scripts or other files are copied into the assets folder. Lastly I removed all Custom Packages and removed all but 1 Unity Package

    Recompile with 0 Custom Packages
    2.552
    2.564
    2.305
    2.682

    Recompile with 24 Custom Packages.
    3.269
    3.233
    3.439
    3.263
    3.139

    Recompile with 0 Custom Packages and only 1 Unity package (default is 39)
    1.852
    2.008
    1.934
    2.040
    1.841

    This suggest that each of my 24 packages get recompiled everytime there is a recompilation. Which from my point of view (but I might be totally mistaken) is a total waste of time, because the packages are readonly!
     
    Last edited: Sep 13, 2021
  3. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    551
    Hi @Alterego-Games,

    You should be able to see which assemblies get compiled and the time it takes in the Editor.log file. Normally, an assembly is only recompiled if one of its scripts has changed or one of the assemblies it references is recompiled. This means changing a script under your project Assets should not cause custom packages to be recompiled. And while there may be additional overhead due to the number of scripts and assemblies, it shouldn't be significant if the assemblies are not recompiled. If you do observe that package assemblies (whether Unity's packages or custom packages of your own) get recompiled unnecessarily or that the number of assemblies directly leads to longer compilation times even when they are not recompiled, please reproduce the problem then Report a Bug from the same Editor session so that the Editor.log includes relevant information to help the developers investigate the issue.