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. Dismiss Notice

Unity compilation speed is slow on Apple M1 (Rosetta 2)

Discussion in 'Editor & General Support' started by sevenhao, Dec 3, 2020.

  1. sevenhao

    sevenhao

    Joined:
    Dec 18, 2018
    Posts:
    1
    Compilation on 2020 Mac mini with M1 chip (16 GB RAM) : 11.6 Seconds
    m1 compilation.png
    Compilation on 2016 macbook (1.2GHz Dual-Core Intel Core m5, 8 GB RAM): 2.3 Seconds
    macbook compilation.png

    Compilation time is measured by UnityEditor.Compilation.CompilationPipeline events.
    Unity version on both machines are 2019.4.15f1

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEditor;
    3. using UnityEditor.Compilation;
    4. using UnityEngine;
    5.  
    6. namespace Editor
    7. {
    8.     [InitializeOnLoad]
    9.     public class Startup
    10.     {
    11.         private static double compileStartTime;
    12.  
    13.         private static Dictionary<string, double> assemblyCompileStartTime;
    14.         static Startup()
    15.         {
    16.             CompilationPipeline.compilationStarted += OnCompilationStart;
    17.             CompilationPipeline.compilationFinished += OnCompilationFinished;
    18.             CompilationPipeline.assemblyCompilationStarted += OnAssemblyCompilationStarted;
    19.             CompilationPipeline.assemblyCompilationFinished += OnAssemblyCompilationFinished;
    20.             assemblyCompileStartTime = new Dictionary<string, double>();
    21.         }
    22.  
    23.         static void OnAssemblyCompilationStarted(string path)
    24.         {
    25.             assemblyCompileStartTime[path] = EditorApplication.timeSinceStartup;
    26.         }
    27.        
    28.         static void OnAssemblyCompilationFinished(string path, CompilerMessage[] compilerMessages)
    29.         {
    30.             double compileTime = EditorApplication.timeSinceStartup - assemblyCompileStartTime[path];
    31.             Debug.Log(path + ":" + compileTime + "s");
    32.         }
    33.  
    34.         static void OnCompilationStart(object sender)
    35.         {
    36.             compileStartTime = EditorApplication.timeSinceStartup;
    37.         }
    38.  
    39.         static void OnCompilationFinished(object sender)
    40.         {
    41.             double compileTime = EditorApplication.timeSinceStartup - compileStartTime;
    42.             Debug.Log("Compile Time Total:" + compileTime + "s");
    43.         }
    44.  
    45.     }
    46. }
    I understand that Unity Editor is not running natively on Apple Silicon, and running on Rosetta2 might slow things down a little. But why is the compilation almost 5 times slower?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    My complete wild guess is because Apple couldn't be bothered to translate several of the newer x86_64 extensions in Rosetta 2. Apple has publicly stated they won't translate AVX for example, and the Roslyn compiler used by Unity is known to use AVX if available. It would be interesting to get a complete list of all unsupported x86_64 instructions from Apple, and then disable them all on an Intel Mac, and see how the performance stacks up. But for some reason all the info I can find from Apple is AVX is just an example of what isn't supported, but the list likely includes more or they wouldn't be so vague.

    https://developer.apple.com/documentation/apple_silicon/about_the_rosetta_translation_environment
     
    Last edited: Dec 3, 2020
  3. Isfaq

    Isfaq

    Joined:
    Feb 2, 2017
    Posts:
    161
    Can you test the compilation time in Unity 2020.2b?
     
  4. lionel_wang

    lionel_wang

    Joined:
    Oct 7, 2019
    Posts:
    2
    still slow
     
  5. travisschau

    travisschau

    Joined:
    Mar 27, 2013
    Posts:
    13
    Same experience here, would love to know if there's anything I can do to streamline this - or if help is coming either from Unity or OS updates. It's surprisingly slow even in a very simple project.. every time I bounce back to Unity from Rider, there's a 5-10 second lag.

    Running 2019.4.17f1
     
  6. JohnnyFactor

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    343
    This was answered here: https://forum.unity.com/threads/uni...es-and-workarounds.929220/page-4#post-6604516

    I don't believe there is any way around this (other than what the link shares). Every time you modify a script, it needs to be retranslated to Rosetta again after compiling. The only real solution will be a native M1 Unity-- probably a year from now at best.
     
    travisschau likes this.
  7. LLZ_T

    LLZ_T

    Joined:
    Apr 22, 2020
    Posts:
    8
    And here we are in 2021, nearly at the year mark after the last post and still Unity is running like .... on the M1