RunTimeTypedWrapper : Avoid unnecessary GIL acquisitions#1535
Open
johnhaddon wants to merge 4 commits into
Open
RunTimeTypedWrapper : Avoid unnecessary GIL acquisitions#1535johnhaddon wants to merge 4 commits into
johnhaddon wants to merge 4 commits into
Conversation
There is nothing in Cortex itself that depends on the statically allocated `TypeId::Class*ParameterTypeId` enumeration values. It is possible that recently removed modules such as IECoreNuke might depend on them as keys in parameter-handling registries. But two options are available there : 1. Use `RunTimeTyped::typeIdFromTypeName()` to get the TypeId. This will require that the `IECore` Python module is imported first. 2. Key the registry using type names instead of IDs.
This guarantees that all RunTimeTyped subclasses implemented in Python have TypeIds in the Range FirstPythonTypeId-LastPythonTypeId. We'll make use of that property in the next commit.
These could absolutely destroy performance in Gaffer, resulting in workarounds of the sort seen in GafferHQ/gaffer@11b7361. Despite these, we're still finding casts that are hitting Python unnecessarily, now during ShaderNetwork generation. Now we have guaranteed that all Python classes have TypeIds in a specific range, we can avoid the GIL lock entirely for any casts to types known to be implemented in C++. This will let us remove all the workarounds in Gaffer, and be confident that we won't find other examples of performance-destroying casts in future.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This avoids a big performance hit when a
runTimeCast<SomeC++Type>()is performed on an instance of a Python-based RunTimeTyped subclass. We do many such casts in Gaffer, and were resorting to some nasty workarounds to avoid the overhead of GIL acquisition for the most common cases. Despite this, we're still finding new variants of casts with unwanted overhead, so fixing this once and for all in Cortex has become critical.