imageworks/OpenShadingLanguage — pull request #366 by lgritz (2014-05-06 17:52:40+00:00)
Title: OSL format() speedup

ustring construction is relatively slow (by design, it's assumed to be infrequent). If we happen to be constructing strings in the shader using many calls to format() which are usually making the same strings over and over, we can actually speed up by having the ShadingContext remember the last ustring created by format, and if it matches the string we just made, we can return the ustring directly without having to construct it again.

In my contrived tests that emphasize ustring creation bottleneck (see https://github.com/OpenImageIO/oiio/pull/846 for explanation), I'm seeing an additional 10% speedup with this patch on the OSL side. On several production asset frames I've tried, I'm getting essentially the same speed as before. So while in theory an "incoherent" construction of strings would be doing slightly more work by performing this check before ustring construction, in practice I'm not seeing any slowdown on actual scenes. So I suspect that scenes either have infrequent ustring construction and are not affected, or have VERY frequent but extremely coherent ustring construction and are sped up. Frequent but incoherent seems harder to find in the wild.