imageworks/OpenShadingLanguage — pull request #88 by lgritz (2011-11-01 16:20:35+00:00)
Title: Review: greedyjit

New SS option "greedyjit", if nonzero, will remember all created shader groups and optimize/JIT them all up front, concurrently, without locking, the first time any one executes.

This may end up optimizing/JITing shader groups that never need to execute, and also may worsen "time to first pixel." But if you tend to JIT most of the shaders you specified anyway, this will make sure it's done with perfect parallelism, no locking.

Even if a renderer doesn't want this enabled generally, turning it on selectively is also great for debugging problems with OSL compilation, since it forces all shaders to optimize/jit very early in the render. It sucks when there's a bug in OSL's optimizer, showing up only in a shader that's first used 7 hours into a render. Not that I have any experience with that, no sir.

N.B. The app itself doesn't need to be aware of the multithreading; this spawns a bunch of new threads for the compilation, which will subsequently be terminated when all the shaders have been compiled. It will make as many threads as there are cores, which, if there are several renders on the box simultaneously, may briefly be "over-threading". But I don't see much harm in that, it should be for only a tiny fraction of the time of a render and doesn't retain any more memory than it would have originally (just the JITed bytes).