-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-44945: Specialize BINARY_ADD #27967
bpo-44945: Specialize BINARY_ADD #27967
Conversation
🤖 New build scheduled with the buildbot fleet by @markshannon for commit a22af9a 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except for the specialization for inplace strings (it causes refleaks, see below).
} | ||
if (left_type == &PyUnicode_Type) { | ||
int next_opcode = _Py_OPCODE(instr[1]); | ||
if (next_opcode == STORE_FAST) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this check alone is enough, seems pretty easy to trick it with something like s = y + ''
. Then again the runtime check DEOPT_IF(var != left, BINARY_ADD);
will catch that.
@@ -121,7 +121,8 @@ _Py_GetSpecializationStats(void) { | |||
int err = 0; | |||
err += add_stat_dict(stats, LOAD_ATTR, "load_attr"); | |||
err += add_stat_dict(stats, LOAD_GLOBAL, "load_global"); | |||
err += add_stat_dict(stats, LOAD_GLOBAL, "load_method"); | |||
err += add_stat_dict(stats, LOAD_METHOD, "load_method"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops, thanks for fixing this.
🤖 New build scheduled with the buildbot fleet by @markshannon for commit 3146f48 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
STAT_INC(BINARY_ADD, hit); | ||
record_hit_inline(next_instr, oparg); | ||
GETLOCAL(next_oparg) = NULL; | ||
Py_DECREF(left); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ignore, but you can reorder this to
PyUnicode_Append(&SECOND(), right);
STACK_SHRINK(1);
Py_DECREF(right);
Py_DECREF(left);
if (TOP() == NULL) {
goto error;
}
Then if you'd like, you can factor out the code from STACK_SHRINK(1);
onwards into a BINARY_ADD_FOOTER
macro, and reuse that for all BINARY_ADD_*
instructions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to avoid using macros.
IMO, macros only help readability if they are function like, and self descriptive. E.g. Py_DECREF
.
Failure on buildbot/AMD64 Arch Linux Asan Debug PR is a persistent failure unrelated to this PR. |
Adds the following specializations:
BINARY_ADD_UNICODE_INPLACE_FAST
is needed to keepfor ...: s = s + ...
O(ln(n)), rather than O(n**2).About 1% faster
https://bugs.python.org/issue44945