Commit a1d8c315 authored by Kevin Modzelewski's avatar Kevin Modzelewski Committed by Kevin Modzelewski

A few small getattr slowpath microoptimizations

- call PyType_Check instead of isSubclass
- unlikely()
- object_cls gets checked all the time but only has attributes that
  start with '_'
parent 7d9da5ef
......@@ -5,6 +5,15 @@ def f():
g = getattr
c = C()
c.o = 1
for i in xrange(10000000):
for i in xrange(1000000):
g(c, "o")
g(c, "o")
g(c, "o")
g(c, "o")
g(c, "o")
g(c, "o")
g(c, "o")
g(c, "o")
g(c, "o")
g(c, "o")
f()
......@@ -43,6 +43,8 @@ static Box* setOption(Box* option, Box* value) {
else CHECK(REOPT_THRESHOLD_BASELINE);
else CHECK(OSR_THRESHOLD_BASELINE);
else CHECK(SPECULATION_THRESHOLD);
else CHECK(ENABLE_ICS);
else CHECK(ENABLE_ICGETATTRS);
else raiseExcHelper(ValueError, "unknown option name '%s", option_string->data());
return None;
......
......@@ -714,7 +714,7 @@ Box* Box::getattr(BoxedString* attr, GetattrRewriteArgs* rewrite_args) {
HCAttrs* attrs = getHCAttrsPtr();
HiddenClass* hcls = attrs->hcls;
if (hcls->type == HiddenClass::DICT_BACKED) {
if (unlikely(hcls->type == HiddenClass::DICT_BACKED)) {
if (rewrite_args)
assert(!rewrite_args->out_success);
rewrite_args = NULL;
......@@ -728,7 +728,7 @@ Box* Box::getattr(BoxedString* attr, GetattrRewriteArgs* rewrite_args) {
assert(hcls->type == HiddenClass::NORMAL || hcls->type == HiddenClass::SINGLETON);
if (rewrite_args) {
if (unlikely(rewrite_args)) {
if (!rewrite_args->obj_hcls_guarded) {
if (cls->attrs_offset < 0) {
REWRITE_ABORTED("");
......@@ -1001,9 +1001,20 @@ Box* typeLookup(BoxedClass* cls, BoxedString* attr, GetattrRewriteArgs* rewrite_
return NULL;
} else {
assert(attr->interned_state != SSTATE_NOT_INTERNED);
assert(cls->tp_mro);
assert(cls->tp_mro->cls == tuple_cls);
for (auto b : *static_cast<BoxedTuple*>(cls->tp_mro)) {
// object_cls will get checked very often, but it only
// has attributes that start with an underscore.
if (b == object_cls) {
if (attr->data()[0] != '_') {
assert(!b->getattr(attr, NULL));
continue;
}
}
val = b->getattr(attr, NULL);
if (val)
return val;
......@@ -1674,7 +1685,7 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew
}
if (!cls_only) {
if (!isSubclass(obj->cls, type_cls)) {
if (!PyType_Check(obj)) {
// Look up the val in the object's dictionary and if you find it, return it.
Box* val;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment