Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Incremental C# Compiler for faster compilation

Discussion in 'Scripting' started by United-Unity, Jan 14, 2016.

  1. United-Unity

    United-Unity

    Joined:
    Mar 25, 2015
    Posts:
    20
    Hello!

    Let me introduce "Incremental C# Compiler" to you.
    Incremental C# Compiler can compile C# sources faster than Unity-Mono one because it can detect changed sources and do work with only those changes.

    If the size of source of your project exceeds 1MB, this compiler will help.
    (otherwise unity-mono is not that slow ;))

    This is a still experimental tool and only works on unity editor for windows.
    https://github.com/SaladbowlCreative/Unity3D.IncrementalCompiler

    Thanks!
     
    nirvanajie, WinterboltGames and m0guz like this.
  2. doppioslash

    doppioslash

    Joined:
    Dec 22, 2015
    Posts:
    2
    Hi United,

    looks pretty cool.
    How does it behave with Unity's hot swapping?
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,199
    You've written that parts of this is based on alexzzzz' work. This sounds like a straight upgrade. Have you considered trying to get this merged upstream with that project, or is the two projects too different?

    I also wonder about the hot swapping.
     
  4. United-Unity

    United-Unity

    Joined:
    Mar 25, 2015
    Posts:
    20
    Sorry for late reply. Because hot swapping is up to Unity itself, it should work well.
     
  5. United-Unity

    United-Unity

    Joined:
    Mar 25, 2015
    Posts:
    20
    Sorry for late reply. I thought that incremental compiler was one of compilers supported by his work.
    But recently driver code borrowed from it has been diverged so it's better to keep it separate ;)
     
  6. WinterboltGames

    WinterboltGames

    Joined:
    Jul 27, 2016
    Posts:
    257
    Awesome! but are you still working on it and doing updates?
     
  7. x4000

    x4000

    Joined:
    Mar 17, 2010
    Posts:
    352
    This seems quite slick indeed! I'm trying to get it to run on Unity 2017.1.1p1 at the moment, and running into the following error, however:

    System.NullReferenceException: Object reference not set to an instance of an object
    at CSharp60SupportActivator.GetSupportedLanguages () [0x00000] in <filename unknown>:0
    at CSharp60SupportActivator..cctor () [0x00000] in <filename unknown>:0
    UnityEditor.EditorAssemblies:processInitializeOnLoadAttributes()

    From the source code, I see that the problem is here:

    private static List<SupportedLanguage> GetSupportedLanguages()
    {
    var fieldInfo = typeof(ScriptCompilers).GetField("_supportedLanguages", BindingFlags.NonPublic | BindingFlags.Static);
    var languages = (List<SupportedLanguage>)fieldInfo.GetValue(null);
    return languages;
    }

    It looks like the unity API has changed a bit, probably in anticipation of their removal of UnityScript. However, I'm not sure what to change this to in order to get the behavior you were previously seeing, nor do I know how to easily recompile the IncrementalCompiler.exe, where the problem seems to be. I did do a recompile of that, but the resulting file size was only 30KB and it had another 30ish files that are mostly .net assemblies pulled in alongside it. The original executable is more like 7 meg, so I expect it must be including quite a bit of those external assemblies compiled into itself or something of that nature.

    I've also tried running the build.cmd file -- with success -- but there was not a lot that was generated that was of obvious use to my particular case. Any ideas?

    Fantastic work you've been doing here.
     
  8. x4000

    x4000

    Joined:
    Mar 17, 2010
    Posts:
    352
    Well -- moving to Unity 2017.3 beta and converting everything into separate dlls via the new script compilation assembly definitions seems to have fixed it for me.

    The documentation, if you haven't seen it: https://docs.unity3d.com/2017.3/Documentation/Manual/ScriptCompilationAssemblyDefinitionFiles.html

    I've turned back on the windows search indexer and that seems not to make a difference anymore. The "hang after compile" time has pretty much disappeared, and that's with logging still on. The actual import and compilation times are, side-by-side, almost twice as fast as Unity 2017.1 even for things that aren't scripts.

    They've made a lot of strides, for sure. The compilation time itself is still pretty bad, but at least now we can split that apart and have less compiling all at once. The downside is increased project complexity, regarding dependencies and so forth.

    I'm down from a 31+ second turnaround time from code changes to being able to hit play in the editor, to closer to 9, and that's with a lot of background stuff hitting my disk during that particular test, so it wasn't really a fair fight. Really it's more like 5 or 7 seconds if I didn't have an svn commit and some audio transcoding going on in separate processes in the background.

    So... definitely worth an upgrade. For what it's worth, stability has been good so far with beta 9. I think it's supposed to leave beta by the end of this month.
     
    nirvanajie likes this.
  9. friuns3

    friuns3

    Joined:
    Oct 30, 2009
    Posts:
    307
    x4000 or you can use just plugins folder, but Incremental C# Compiler been still 3 times faster would be nice to see update for 2017
     
  10. x4000

    x4000

    Joined:
    Mar 17, 2010
    Posts:
    352
    This was with using the plugins folder, and with using the standard assets folder as well.
     
  11. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Can confirm what @x4000 is saying. Had a very similar experience that was, at least partially, solve by custom assemblies.

    With older Unity versions, Incremental Compiler was very useful. Especially since it brought C#6 to the table, along with faster compile times. Updating it to Unity 2017.3+ might not be trivial, since we now have custom assembly definitions.
     
    nirvanajie and x4000 like this.