Skip to content

Commit d56420f

Browse files
committed
profile a little more in PyObjectLookupAttr
1 parent 36f4905 commit d56420f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectLookupAttr.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.oracle.truffle.api.frame.Frame;
7070
import com.oracle.truffle.api.frame.VirtualFrame;
7171
import com.oracle.truffle.api.nodes.Node;
72+
import com.oracle.truffle.api.profiles.ConditionProfile;
7273

7374
/**
7475
* Equivalent to use for the various PyObject_LookupAttr* functions available in CPython. Note that
@@ -148,11 +149,13 @@ static final Object doBuiltinModule(VirtualFrame frame, Object object, String na
148149
@Cached ReadAttributeFromObjectNode readNode,
149150
@Cached ReadAttributeFromObjectNode readGetattr,
150151
@Shared("errorProfile") @Cached IsBuiltinClassProfile errorProfile,
152+
@Cached ConditionProfile noValueFound,
151153
@Cached CallNode callGetattr) {
152154
Object value = readNode.execute(object, cachedName);
153-
if (value == PNone.NO_VALUE) {
155+
if (noValueFound.profile(value == PNone.NO_VALUE)) {
154156
Object getAttr = readGetattr.execute(object, SpecialMethodNames.__GETATTR__);
155157
if (getAttr != PNone.NO_VALUE) {
158+
// (tfel): I'm not profiling this, since modules with __getattr__ are kind of rare
156159
try {
157160
return callGetattr.execute(frame, getAttr, name);
158161
} catch (PException e) {
@@ -179,15 +182,15 @@ static final Object doBuiltinType(VirtualFrame frame, Object object, String name
179182
@Cached("create(name)") LookupAttributeInMRONode lookupName,
180183
@Bind("lookupName.execute(type)") Object descr,
181184
@Cached ReadAttributeFromObjectNode readNode,
182-
@Cached ReadAttributeFromObjectNode readGetattr,
185+
@Cached ConditionProfile valueFound,
183186
@Cached("create(__GET__)") LookupInheritedAttributeNode lookupValueGet,
187+
@Cached ConditionProfile noGetMethod,
184188
@Cached CallTernaryMethodNode invokeValueGet,
185-
@Shared("errorProfile") @Cached IsBuiltinClassProfile errorProfile,
186-
@Cached CallNode callGetattr) {
189+
@Shared("errorProfile") @Cached IsBuiltinClassProfile errorProfile) {
187190
Object value = readNode.execute(object, cachedName);
188-
if (value != PNone.NO_VALUE) {
191+
if (valueFound.profile(value != PNone.NO_VALUE)) {
189192
Object valueGet = lookupValueGet.execute(value);
190-
if (valueGet == PNone.NO_VALUE) {
193+
if (noGetMethod.profile(valueGet == PNone.NO_VALUE)) {
191194
return value;
192195
} else if (PGuards.isCallable(valueGet)) {
193196
try {

0 commit comments

Comments
 (0)