[interop] Cache subclass checks #116
All Vouch review confidence checks passed
Residual risk 0.02 = Change Risk (0.20) × (1 − Review Confidence (0.90)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.20 · 15 lines diff across 1 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.91 · 3 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.166
Real PR Conversation Timeline
4 items
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?
Here IsComplete is only expensive the first time for ROOT then should be cheap. Is that not the case?
Thanks for the comments! I'll address them later. For now, what is also important to know is that the PRs I'm opening today all address significant performance regressions in the ROOT tutorials or CMS Combine workflows with the cppjit upgrade in ROOT.
vgvassilev
guitargeek
Passing an object of a derived class to a formal base-class argument, as well as binding a method call whose 'self' is an instance of a class derived from the method's declaring class, makes the bindings check interop::IsSubclass() on every call, and the clang derivation check is not free.
Memoize IsSubclass() per class pair in the interop wrapper, where the calls are already serialized by the interop lock. A class that is still incomplete can gain bases once its definition is loaded, so a negative answer is only cached when both classes are complete.
For example, calling a C++ function that takes a base-class reference with a derived instance:
import time
import cppjit
cppjit.cppdef(r"""
struct SubBase {
virtual ~SubBase() = default;
virtual int value() const { return 1; }
};
struct SubDerived : SubBase {
int value() const override { return 2; }
};
int take_base(const SubBase& b) { return b.value(); }
""")
d = cppjit.gbl.SubDerived()
cppjit.gbl.take_base(d) # warm-up
start = time.perf_counter()
for _ in range(200000):
cppjit.gbl.take_base(d)
print(f"200k calls: {time.perf_counter() - start:.2f} s")
This takes 0.08 s instead of 0.22 s per 200k calls in a pristine build (0.18 s with only the parent commit's caches applied; ~2x further). Release build against the pinned CppInterOp, min of 7 repetitions, interleaved A/B. An instrumented build confirms the converter queries IsSubclass() once per call on this path, so the saved cost is the clang derivation check itself.