I finally got time to look into the stripping tool that was introduced with Unity 6.1 (com.unity.web.stripping-tool) and got it working with my CI setup (Github).
First, here are two builds, once with stripping, once without:
I’m quite a bit underwhelmed for now and ran into multiple issues / questions. Here is my current feedback:
In the build link you can see, that the stripped folder is quite a bit bigger. This is because of the two files functions.json and labels.json. When removing those files I get constant errors in the console (but the build is running). Can I get rid of those? Otherwise I don’t really see the benefit of stripping.
I tried using StrippingProjectSettings.ActiveSettings to get the default stripping settings I set, but this didn’t work for CI builds. I went ahead and fixed it by loading a ScriptableObject that links to the settings (commit), but I was quite a bit disappointed to be needing this workaround.
When I had 2D renderer disabled I got two errors in the console:
Stripped function SpriteAtlasManager::SpriteAtlasManager(MemLabelId)::EarlyUpdateSpriteAtlasManagerUpdateRegistrator::Forward() (used in submodule ‘2D Rendering Sprite Atlas’) was called.
This could be caused by a submodule being stripped from the build even though it is needed.
Try disabling the submodule ‘2D Rendering Sprite Atlas’ in Submodule Stripping Settings.
Stripped function CleanupSpriteBatchGroup(void*) (used in submodule ‘2D Rendering Renderer’) was called.
This could be caused by a submodule being stripped from the build even though it is needed.
Try disabling the submodule ‘2D Rendering Renderer’ in Submodule Stripping Settings.
This was a bit surprising for me, since the project is a very simple 3D camera with cubes, but no 2D from my knowledge
The benefit for this project (especially when looking at the compressed sizes) is quite underwhelming. From my understanding this would not get bigger for bigger projects (apart from maybe Json.NET?). Or can I expect better improvements in bigger projects?
Yeah, so that’s what I found so far. I was a bit surprised to not find too many discussions on the forum on the topic.
Thank you for trying out the Web Stripping Tool and giving us feedback.
Those files are used in the case a stripped function gets called to log a useful error message. If you want to get rid of those files you can change the “Missing Submodule Error Handling” setting to “Ignore”. However, these files will have no impact on startup time since they are loaded asynchronously. The game can already start running when the files are still being downloaded in the background.
I guess you are starting the editor in batch mode in your CI setup? I will try to reproduce this bug and log it. The StrippingProjectSettings.ActiveSettings are stored in the project settings and should be automatically set when the project is loaded. Maybe there is an issue with this mechanism in batch mode.
How did you select the submodules to remove in your project? Did you use the submodule profiling feature of the package? This will automatically detect what submodules are unused during a profiling run and create a report that you can import back into the tool.
The reason some of the 2D Rendering submodules are used in your project could be due to the UI in your game. This also uses the 2D Rendering features.
What stripping settings did you use for testing? Did you also enable “Optimize Code After Stripping”? This options takes a while but it runs additional code optimization passes after the submodules are removed from the WebAssembly file, e.g., dead code removal, inlining, duplicate function merging. In my experience this will have a pretty significant impact on code size.
Overall the size savings of course highly depend on what Unity features your project is using and how well the existing code stripping features are able to work(Managed Stripping, compiler optimization). If you have a lot of code that can not be stripped by the other mechanisms you will see higher gains.
I just did a quick test with your project and this is what I was able to achieve this:
Base Optimized Build
Stripped Build
Compressed WASM size
2.515.095 bytes (2.40 MB)
2.443.135 bytes (2.30 MB)
Umcompressed WASM size
9.480.942 bytes (9,04 MB)
8.785.418 bytes (8.37 MB)
My baseline build is slightly larger so I don’t know what happend there and if you used different settings.
I used different build settings for the baseline optimized build and the one I used for stripping. There are some options that are required for the best submodule stripping that are not optimal for a build that will not use the submodule stripping tool(Debug Symbol Mode, Submodule Stripping Compatibility).
Here are the settings I used:
Thanks a lot for your thorough answer, this helps a lot! I took you settings and started some new builds (Which you can easily reproduce by using the Menu Item Tools->Build WebGL->minsize-stripping-webgl2). Here are the new results:
so the reduction is ~600KB uncompressed and ~80KB compressed. I guess I was hoping for a bit more than 3% size reduction, but looking at the uncompressed size I can see that this is quite an improvement.
Yes, I was using Optimize Code after Stripping, here is the file I’m using.
Since this is a project with very little custom user code. Do you have rough numbers for how e.g. a 10 MB compressed wasm file will change?
Yep exactly, running game.ci, you can see the workflow here. I also could imagine that the problem comes from the settings not being properly loaded. Side note: The settings file somehow duplicates the data and is not nice from a version control perspective (one line which is hard to read).
I tried it, but somehow got all modules listed as being strippable, therefore I didn’t try it any further, but maybe something else was off at that time
So there I can see an almost 8% reduction (480KB) in the total download size needed for the project, which is quite cool! The size reduction for both URP & Builtin RP are still not compensating how much the engine grew since 2023.1 (as in with versions <=2023.1 you will get smaller builds than with submodule stripping), but it is still nice to have this tool. Looking forward how far this can be pushed!
Web Stripping Tool currently does not strip IL2CPP metadata (global-metadata.dat) to further reduce the build size. Is it possible to add support for this in the future?