Created
January 15, 2021 15:56
-
-
Save hybridherbst/1240e67332f61b839add1a08b5f76d58 to your computer and use it in GitHub Desktop.
Set the number of concurrent compiler threads for Unity3D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
using UnityEditor; | |
using UnityEngine; | |
public static class SetThreadCount | |
{ | |
[InitializeOnLoadMethod] | |
static void Init() | |
{ | |
// change this to test out different configurations | |
// in my tests there were pretty negligible performance differences between various options (*2, *4, *0.5) | |
// an easy way to test compilation performance is with https://github.com/needle-tools/compilation-visualizer | |
int threadCount = SystemInfo.processorCount; | |
if (threadCount != SystemInfo.processorCount) { | |
// EXPERIMENT: set thread count for compilation "UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface" | |
var eci = Type.GetType( | |
"UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface, UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"); | |
if (eci != null) { | |
var instanceProp = eci.GetProperty("Instance", (BindingFlags) (-1)); | |
if (instanceProp != null) { | |
var instance = instanceProp.GetValue(null); | |
var setComp = instance.GetType().GetMethod("SetMaxConcurrentCompilers", (BindingFlags) (-1)); | |
setComp?.Invoke(instance, new object[] { threadCount }); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment