Speeding up Reload Assemblies in Unity3D

Problem

I ran into a problem with Unity 2021.3.x LTS where reloading assemblies was taking several minutes. This would happen when running automated tests, when entering play mode, and sometimes when making small code changes.

These loading times are too slow to allow for the kinds of rapid iteration needed for productive game development.

The most frequent recommendation for slow compile times is to use Assembly Definitions. My project already makes extensive use of Assembly Definitions and should only need to compile a small set of scripts when I make changes, so this was not the cause of my problem.

I spent a significant amount of time researching the problem and found this forum discussion. Based on that, it seemed that something had been introduced to Unity since 2019.LTS. I tried the suggestions there, but could not get my load times to go any faster.

Solution (?)

I got out the profiler and confirmed that the loading time was, in fact, due to a ReloadAssemblies call.

ReloadAssemblies is too slow

A significant portion of that time was taken by BurstCompiler.DomainReload. Perhaps this explains why I didn’t see this behavior in 2019.LTS; I didn’t use Burst. Using some search engine magic, I found two pages of Unity Documentation that seem to have helped.

This lead me to these settings found in Edit/Project Settings.

Results

Running my automated tests and entering play mode no longer trigger reloading assemblies.

I’ve only just solved this a few minutes before writing this post. Time will tell if this is a reasonable long term solution; for now, I’m much happier.

Risks

By disabling the domain reload, it’s possible that I’ll experience some unexpected behaviors, especially around static variables. In general, I try to avoid writable static variables, so I don’t anticipate much of a problem in my use case; however, if you make frequent use of writable static variables, disable Domain Reload with caution. I imagine this could lead to some stealthy little bugs.