Compiling cpp for libil2cpp takes too long

When I start Unity for the first Android build, it takes over 2 hours. Subsequent builds complete in about 5 minutes.

However, after every restart, it again takes more than 40 minutes for the first build. I suspect the cache is being cleared somehow, but I’m not sure why. This issue has become extremely frustrating.

I was using Unity 2022.3.19F1 and tried the following solutions, but none worked:

  • Deleting the Library folder
  • Resetting the project setup
  • Unchecking Settings > Optimization > Optimize Mesh Data
  • Running Unity in administrator mode
  • Ensuring both Unity and projects are on an SSD
  • Adding the folder as an exception in Bitdefender antivirus
  • Removing the antivirus
  • Increasing the maximum cache size (File → Preference → GI Cache → Maximum Cache Size (GB) 200)
  • Updating to the new version 2022.3.28f1 and applying all the above solutions

I analyzed the profiler in Chrome from the build report and found that UpdateFromStreamAsync is consuming most of the time. The buildReport.json is attached for your reference.

Please help, as this issue is significantly slowing down our development and testing process.

FYI, buildreport extension is changed to txt because json was not allowed to upload

9862842–1421040–buildreport.txt (7.01 MB)

I did a normal compile with IL2CPP and it took 40 minutes, after which I just aborted. next thing I did was change the setting Project settings → Player → Android → Other Settings → Configuration → IL2CPP Code generation. I changed it from “Faster runtime” to “Faster (smaller) builds”. Not sure about performance but if you just want to test something this is what I do.

Edit: total compilation took 10 minutes on my 4 core notebook after the change