imageworks/OpenShadingLanguage — pull request #154 by lgritz (2012-09-13 21:49:01+00:00)
Title: Reduce instance symbol memory use, lowering OSL-related mem by 1/2-2/3 for large scenes

Reduce instance symbol memory use, lowering OSL-related mem by 1/2-2/3 for large scenes

Background: The shader master (one copy for each distinct shader) holds
the full symbol table. When a shader instance ("node/layer") is
created, it copies just the portion of this symbol table that holds the
parameters, which are the only symbols that can be overridden by the
instance, compared to the master's copy. When the shader is optimized
and JITed, the rest of the symbol table is copied from the master, the
optimization and JIT happens, then the instance's symbol table is freed.

But, if you have enough instances, and they have enough parameters, even
just storing the parameter part of the symbol table for each instance
really adds up. For example, a production frame I was testing had 977
shader groups consisting of a total of 280,066 instances, for which the
statistics report that OSL uses a peak of 1.4 GB (of a total RSS size of
6.1 GB).

With this patch, only a few fields in the symbol table are overridden by
the instance. Store just those fields, then combine them with the
master's symbol table at the last moment for optimization/compile. I
also removed a few fields and methods entirely from the Symbol class,
which were obsolete and no longer used.

Result: The test scene mentioned above improved OSL memory use from 1.4
GB peak to 590 MB peak, and reduced process RSS for the render overall
from 6.1 GB to 4.4 GB. There is no change in runtime, this is just a
memory savings, not a time/memory tradeoff.