Skip to content

Commit 0a1d122

Browse files
committed
[GR-31093] Faster multi-context MRO lookup for builtin types.
PullRequest: graalpython/1777
2 parents 2e3e3a7 + a6a2a97 commit 0a1d122

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/LookupAttributeInMRONode.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,31 @@ protected static Object lookupPBCTCachedMulti(@SuppressWarnings("unused") Python
177177
return cachedValue;
178178
}
179179

180-
@Specialization(replaces = "lookupPBCTCached")
180+
public static PythonBuiltinClassType findOwnerInMro(PythonCore core, PythonBuiltinClassType klass, Object key) {
181+
PythonBuiltinClassType current = klass;
182+
ReadAttributeFromDynamicObjectNode readNode = ReadAttributeFromDynamicObjectNode.getUncached();
183+
while (current != null) {
184+
if (readNode.execute(core.lookupType(current), key) != PNone.NO_VALUE) {
185+
return current;
186+
}
187+
current = current.getBase();
188+
}
189+
return null;
190+
}
191+
192+
@Specialization(replaces = "lookupPBCTCached", guards = "klass == cachedKlass", limit = "getAttributeAccessInlineCacheMaxDepth()")
193+
protected Object lookupPBCTCachedOwner(@SuppressWarnings("unused") PythonBuiltinClassType klass,
194+
@Cached("klass") @SuppressWarnings("unused") PythonBuiltinClassType cachedKlass,
195+
@Cached("findOwnerInMro(getCore(), cachedKlass, key)") PythonBuiltinClassType ownerKlass,
196+
@Cached ReadAttributeFromDynamicObjectNode readAttrNode) {
197+
if (ownerKlass == null) {
198+
return PNone.NO_VALUE;
199+
} else {
200+
return readAttrNode.execute(getCore().lookupType(ownerKlass), key);
201+
}
202+
}
203+
204+
@Specialization(replaces = "lookupPBCTCachedOwner")
181205
protected Object lookupPBCTGeneric(PythonBuiltinClassType klass,
182206
@Cached ReadAttributeFromDynamicObjectNode readAttrNode) {
183207
return findAttr(getCore(), klass, key, readAttrNode);

0 commit comments

Comments
 (0)