Hey!
In my game, shader compilation may take up to 30 seconds on startup, but only the first time.
After the first load the shaders are instead loaded from cache and it takes barely 4 seconds for the entire game to be loaded.
Each shader has the vertex AND fragment code in the same .hlsl file.
Then I had a thought that stuck with me for a couple of weeks... What if the shaders are instead split in two files, one for vertex and one for fragment?
I thought, would that make the compilation time faster?
Since the compilation must remove variables/code it does not use, it would be logical it would skip that step almost completely if it was two files instead of one.
The only question is, how much time would it save?
So I went to work and took a bloated shader in my game and copied it 50 times to new shader materials with unique names.
Then I compiled them from code by loading them in with a resource group, first the version with 50 vs/fs shaders in the same file and then the second version with 50 vs/fs shader in two different files.
The results are:
Loaded and compiled 50 shaders in combined vs/fs files (so 50 files in total): 31.693871 seconds
Loaded and compiled 50 shaders with vs/fs split between vertex and fragment (so 100 files in total): 31.36227 seconds
I made this experiment 5 times in a row and the times above are the biggest change between them (but the one with split files were always a tiny bit faster).
So in essence, the time it takes for the compliation by splitting shaders is negligible, as it was never more than an increase of 0.33 seconds while compiling 50 shaders, which is at the highest 1.05% reduced compliation speed.
So in short, do NOT care about splitting shaders, as it is almost completely pointless (and less user friendly)!