I digged around in the threejs source code a bit and from what I understand is that the lights are stored as an uniform array in the fragment shader. The shader iterates over the array in a for loop but this loop is unrolled. So that’s why the shader needs to be recompiled.
I’m wondering if it would be a good idea to add a new uniform with the current light count. And keep the (hardcoded) uniform array the same length, but then skip some of the light rendering based on the dynamic light count.
I’d like to implement this and do a pull request, but it depends on the amount of time I have. It sounds like the system I described is a lot of work to implement and I’m not sure whether or not this would improve performance at all.
Do you have any idea whether this would work or should I just give up the idea right away?