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

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

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

using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Compilation;
using UnityEngine;

namespace Editor
{
    [InitializeOnLoad]
    public class Startup
    {
        private static double compileStartTime;

        private static Dictionary<string, double> assemblyCompileStartTime;
        static Startup()
        {
            CompilationPipeline.compilationStarted += OnCompilationStart;
            CompilationPipeline.compilationFinished += OnCompilationFinished;
            CompilationPipeline.assemblyCompilationStarted += OnAssemblyCompilationStarted;
            CompilationPipeline.assemblyCompilationFinished += OnAssemblyCompilationFinished;
            assemblyCompileStartTime = new Dictionary<string, double>();
        }

        static void OnAssemblyCompilationStarted(string path)
        {
            assemblyCompileStartTime[path] = EditorApplication.timeSinceStartup;
        }
       
        static void OnAssemblyCompilationFinished(string path, CompilerMessage[] compilerMessages)
        {
            double compileTime = EditorApplication.timeSinceStartup - assemblyCompileStartTime[path];
            Debug.Log(path + ":" + compileTime + "s");
        }

        static void OnCompilationStart(object sender)
        {
            compileStartTime = EditorApplication.timeSinceStartup;
        }

        static void OnCompilationFinished(object sender)
        {
            double compileTime = EditorApplication.timeSinceStartup - compileStartTime;
            Debug.Log("Compile Time Total:" + compileTime + "s");
        }

    }
}

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?

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.

Can you test the compilation time in Unity 2020.2b?

still slow

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

This was answered here: __ https://discussions.unity.com/t/799639 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.

1 Like

And here we are in 2021, nearly at the year mark after the last post and still Unity is running like … on the M1