Arowx
1
Literally tens of minutes to build a simple scene some of it with very low CPU usage and some with a multi-core CPU maxed out so can’t do anything else until it’s finished.
Is this getting worse, is Unity now getting us to Bitcoin mine when we build or has my computer got a virus?
Note: Very low GPU usage so probably not Bitcoin mining!
If you setup a new scene with a token cube and build to WebGL/WASM how long does it take your PC/Mac to build?
1 Like
Arowx
2
Started a new project setup a one cube scene and built to WebGL/WASM
Total build time over 58 minutes!
Task Monitored the process and most of that time the process used very little CPU then for the last couple of minutes the process flooded the CPU with high load work.
So is there some way you can speed up the process by using more processing power in earlier stages and ideally limiting the max load for the final stages e.g. 80% max.
Arowx
3
OK Same build to PC takes less about 30 seconds.
Then build to PC but with IL2CPP and it takes over 44 minutes.
Interesting note on second build to PC the build process was a lot faster.
It looks like IL2CPP is not optimised or Unity does not have pre-IL2CPP’d assembely’s as let’s face facts this example has no code in it other than the code built into Unity.
Could Unity not pre-build the default assemblies via IL2CPP and include them in the install to save time…
Or what about more multi-threading for IL2CPP as separate assembely’s will generate separate cpp files right then it’s just compiling them to dlls or the executable.
Are you sure it’s really converting the managed assemblies to C++, or perhaps compiling and linking the massive amount of generated C++ code instead?
In my projects, IL2CPP performance is acceptable, but compiling the generated code is what takes a significant amount of time.
Just tested here :
2018.2 B6 took about less then 3 minutes to build to WebGL/webassembly with a scene + Cube
All other player/build settings were left at default values
Yes, this is something we’re looking at doing. At the moment it is difficult because the IL2CPP build toolchain removes unused IL bytecode from managed assemblies. That means the .NET class library and Unity Engine assembly can be different for each build, depending on what code in them is used but the script code or assemblies in the project. So pre-compiling won’t help. We’re looking for better solutions though.
Also, you may want to consider what your Api Compatibility Level setting is. If you are using the new scripting runtime, try the .Net Standard 2.0 Api Compatibilty Level instead of .NET 4.x. The .Net Standard 2.0 profile has significantly less code to convert and compile than .NET 4.x. In 2018.3 we’ll be making the code even smaller.
3 Likes
Arowx
7
OK I get that after the first run throught, it’s like the build process caches the old build and just rebuilds the files.
Try building to PC/Mac/Linux with IL2CPP set via the PlayerSettings instead of Mono?
I found that switching build targets that still use IL2CPP triggered a slow build process, as opposed to the pre-cached build process when you re-build to the same target.
Arowx
8
I understand that however why does it use such low processor bandwidth, it’s not even using the full capacity of a single core-thread, never mind taking advantage of the full capacity of all available cores?
This strikes me as either their are ‘slowdown bugs’ in the build process or it has not been optimised for throughput.
For example why am I seeing python.exe running in a build process, surely Unity Editor or maybe a Unity Build Manager should be running and managing the process.
What would be a great help would be a better build in progress ui system e.g.

1 Like
The code conversion step (literally IL → C++) is mostly single threaded currently. We’re internally prepping the IL2CPP code to allow it to be multi-threaded, but I’m not sure if or when we will enable that. For most projects though the C++ compilation is the most time consuming part. There we do run many instances of the C++ compiler in parallel.
Unity uses Emscripten to compile the generated C++ code for WebGL, and Emscripten uses python behind the scenes.
I agree, this would be really nice to have. At the moment we’re not working on this, but it is on our radar.
Arowx
10
The thing is it seems very low bandwidth, even single threaded it should be able to max out a core/thread on my CPU?
It could be that your running one file at a time so the bandwidth is limited by a file load then parse/convert and file output style system?
Whereas an asynchronous stream into memory convert in memory and then asynchronous stream out to files could be more productive, the bulk file load and save operations would be limited to storage bandwidth?
Then again why use files surely you could run the process against memory based files streams, if all the files were loaded and saved to memory then this would massively boost performance?
We usually do see one core maxed out during code conversion. At least that is the case when the disk is an SSD. If you are using a HDD, then the performance characteristics might also change. Additionally, you might want to look at disabling a virus scanner for the files in your Unity project (if you are running on Windows). We’ve found that virus scanners can significantly impact file writing performance for IL2CPP.
In general, we try to do as much in-memory as possible though. All of the C++ code generation is done in memory buffers, then later written to files when it is complete, so I don’t think we can gain code conversion performance improvement from that aspect.
Arowx
12
So if you could run IL2CPP completely in memory and stream the files it produces in memory to the C++ compiler could this massively speed up the build process?
What if I set up a RAM drive and store my project there would that have a similar effect on build performance?
I don’t know. I expect that avoiding the file writing would help. However, I don’t think any C++ compilers have a direct memory stream API. In addition, we get some benefits by writing the files to disk, like incremental compilation and debugging ability.
I’m not heard about anyone trying this, but I suppose it cannot hurt.
BTW, make sure to add an exception to your anti-virus program to ignore the project/build folder, Visual Studio (compiler+linker) and Unity. You basically don’t want the AV software to interfere the compiler, which often caused massive slow-downs for me in the past.
1 Like
44 minutes sounds crazy. You might want to look at your system resource usage and figure out where the bottleneck lies. IL2CPP doesn’t write that many files to disk (it used to in the past), so I doubt you’re IO bound unless you’re using an old mechanical drive. I just checked and it takes 57 seconds to build a new Unity project with a cube to Windows IL2CPP on my machine. I doubt your computer is 46 times slower than mine, so I think there’s some software that’s interfering with the build.
Arowx
16
So building to WebGL / WASM roughly involves…
- Stripping Assemblies
- Compiliing C#/JS to IL
- Converting IL 2 C++
- Converting C++ to ASM.js
- Compiling ASM.js to WASM
Could you not just compile from C# to WASM, after all you are just stepping through 4 stages of token conversion when you could just do one.
It’s like someone converting English to Chinese but they only have an English to Dutch, Dutch to German, German to French and French to Chinese dictionaries.
In theory you have all the token conversion tables at each stage why not bypass the middle stages?
Step 5 doesn’t exist. And step 1 and 2 are swapped. This what actually happens:
- Compile C# to IL
- Strip assemblies
- Convert IL to C++
- Compile C++ into WASM.
You can’t compile C# into WASM because stripping needs to be done after C# is compiled to assemblies. And while you could theoretically convert IL to WASM directly, we don’t have such a technology available today.
Some common performance issues include things like:
- antivirus
- drive compression
- etc.
Please try disabling those for the purpose of a test and see if it improves.
Arowx
19
Update: Builds a lot faster now.
Two Things:
- I noticed an odd service/exe running, it was an OVR… exe so I think it was an Occulus Rift feature but as I’m not using the hardware so I uninstalled Occulus VR. It appeared to be sending lots of network data when I was building??
- I have been running 3 yes three anti-virus systems, and as I noticed recently when I virus scanned a folder with all 3 that one is much slower than the others so removed that one.
Side Note: UnityHub seems to be very active networking data why so much and so often?
Tried setting up a ram drive and it seems a bit faster but is limited due to the fact Unity uses a Temp folder in the windows User/Local folder path, for all the intermediate file generation.
Making the idea of setting up a super fast project ram drive for building with Unity a moot point unless…
Is there is a way to specify where Unity locates the Temp (building/linking) folder?
Arowx
20
So what about limiting the speed of asm to wasm, this process goes 100% on my CPU could it be limited to 80% or max-1 cores so at least other processes like watching videos/web browsing do not suffer?