URP shaders have big size

Hi all!
We transfer our project from Unity 2020.3.21 to Unity 2021.3.2 (URP 10.7.0 → 12.1.6).
And after build Addressables groups and recompile shader variants, we have increased bundle size.
After investigating the problem, we saw that the size of compiled shaders in the bundle increased several times!
Unity 2020 shader size:


Unity 2021 shader size:

Why is this happening and how to solve this problem?

My guess (and it is very much a guess) is that the increase in size comes as a side effect of the URP 12 change in shader stripping . As in, in URP 10 lots of helpful stripping of keywords and variants was happening for your shaders and the size was smaller, but when you upgraded to URP 12 it’s no longer automatically reducing the size and number of shaders and you might need to check the shader stripping Project settings and see what you’ve got set up there.

Thnx for reply!
This is our Graphic Project Settings. We have set the value Strip Unused in the Shader Stripping category.8131778--1054928--settings.PNG
Where else are the settings related to stripping?

What does changing Instancing Variants to ‘Strip All’ get you in terms of a decrease of shader size? I had to set my project to ‘Strip All’ to control the exponential increase of compile times when building my project.

Also, in the ‘Player’ tab of the Project Settings, what Graphics APIs are you generating? If you’re generating for DirectX, OpenGL and Vulkan then that’s multiplying the number of shaders required for each of those platforms.

Unity’s blog post on Shader Stripping is the best explanation of how keywords, variants and platforms can cause a ballooning in file size or compile time.

Thank you for your answers. It helped us a lot. If we have any more questions, I’ll be sure to ask them here.

Can we expect a shader build fix from Unity in the future?

Who knows! I’m don’t work for Unity and have no secret info.

I think the changes in URP 12.0 improved things for a lot of people, there’s a forum post here that talks about some of that. Before I was having a lot of build times that stretched on for hours and made regular builds a huge pain, but things have been a lot better for me in in 2021.2. I’d certainly welcome some further improvements to the speed of shader compilation though.