glslang icon indicating copy to clipboard operation
glslang copied to clipboard

Massive performance penalty using non semantic debug info

Open Axel-Reactor opened this issue 5 months ago • 5 comments

We are compiling pretty large GLSL compute shaders (~22k lines). Usually glslang takes a little slow but reasonable ~600ms to do this on my Zen5 desktop machine, but when enabling non semantic debug info this shoots up to >10s.

Axel-Reactor avatar Jul 29 '25 05:07 Axel-Reactor

If you could attach a sample shader, that would make it much easier for us to reproduce the issue. It might also be helpful to specify which platform you're running this on. If you want to do some profiling yourself to try to see where it's spending its time, that would be even better.

arcady-lunarg avatar Jul 29 '25 16:07 arcady-lunarg

Here is one of the shaders (I had to obfuscate the symbols). Not the worst case, but still clearly shows the problem:

$ time glslangValidator -V --target-env vulkan1.4 test.comp 
test.comp

real	0m0.199s
user	0m0.152s
sys	0m0.047s

$ time glslangValidator -gVS -V --target-env vulkan1.4 test.comp 
test.comp

real	0m2.284s
user	0m2.226s
sys	0m0.049s

test.zip

Novum avatar Jul 30 '25 20:07 Novum

Thanks, I can reproduce it with the shader you gave. Running some profiles, I think I understand what's happening. Because nonsemantic instructions only have Id operands, and because line tracking debuginfo is emitted pretty much for each line in your shader, it needs to create an OpConstant instruction for every line number. However, the routine that creates these constant instructions first checks whether one already exists for the requested type and constant, and does so using a simple linear search. This results in a quadratic slowdown that basically depends on the number of unique constants created.

arcady-lunarg avatar Aug 19 '25 00:08 arcady-lunarg

Hey would you be interested in a PR to fix this? If you can point me at that linear search I can give it a go

Axel-Reactor avatar Sep 23 '25 00:09 Axel-Reactor

@Axel-Reactor the linear search is in the findScalarConstant method in SPIRV/SpvBuilder.cpp and is really a result of the fact that the existing constants are stored in a vector in groupedConstants[type] which would probably need to be an unordered_map instead. A PR would certainly be welcome.

arcady-lunarg avatar Sep 23 '25 14:09 arcady-lunarg