imageworks/OpenShadingLanguage — pull request #407 by lgritz (2014-08-28 05:40:43+00:00)
Title: Fix thread contention issue in testshade.

We were doing incredibly stupid in testshade -- setup_shaderglobals was
setting sg.renderstate was asking for
shadingsys->raytype_bit(ustring(raytype)) for EVERY shadde, instead of
finding out which bit it was once and using that int all the time.

Most egregiously, the construction of a ustring was creating thread
contention (it was the SAME ustring every time, which is the worst case
for the locking in the ustring table -- at least if they were different
character sequences, the ustring internals are unlikely to have them
vying for the same lock!).

The net result was that for small shaders especially, the
setup_shaderglobals thread contention could dominated runtime when more
than a few threads were running. This made testshade very unreliable for
benchmarking the actual execution time of short shaders when many
threads were used. Ick!

The fix is very simple, just ask for the bit once globally, and use that
result when setting up the SG's for the individual shades.