Skip to content

RunTimeTypedWrapper : Avoid unnecessary GIL acquisitions#1535

Open
johnhaddon wants to merge 4 commits into
ImageEngine:mainfrom
johnhaddon:runTimeCastWithoutGIL
Open

RunTimeTypedWrapper : Avoid unnecessary GIL acquisitions#1535
johnhaddon wants to merge 4 commits into
ImageEngine:mainfrom
johnhaddon:runTimeCastWithoutGIL

Conversation

@johnhaddon
Copy link
Copy Markdown
Member

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant