Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/interop/interop_wrapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,20 @@ interop::TCppScope_t interop::GetBaseScope(TCppScope_t klass,

bool interop::IsSubclass(TCppScope_t derived, TCppScope_t base) {
std::lock_guard<std::recursive_mutex> Lock(InterOpMutex);
return Cpp::IsSubclass(derived, base);
// Checked on every method call that receives 'self' as its first argument
// (e.g. from pythonizations and protocol slots), so memoize per class
// pair. A class that is still incomplete can gain bases once its
// definition is loaded, so a negative answer is only cached for complete
// classes.
static std::map<std::pair<const void*, const void*>, bool> s_subclass_cache;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The challenge with these cases is error recovery and code reloading/undo. I think this is fine but nominally we should have that in CppInterOp which also should know better when to invalidate these caches. Can we track this in an issue somewhere?

const auto cacheKey = std::make_pair(derived.data, base.data);
auto cached = s_subclass_cache.find(cacheKey);
if (cached != s_subclass_cache.end())
return cached->second;
bool result = Cpp::IsSubclass(derived, base);
if (result || (Cpp::IsComplete(derived) && Cpp::IsComplete(base)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here IsComplete is only expensive the first time for ROOT then should be cheap. Is that not the case?

s_subclass_cache.emplace(cacheKey, result);
return result;
}

static std::set<std::string> gSmartPtrTypes = {
Expand Down
Loading