-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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-42927: Inline cache for slots #24216
Conversation
Something is wrong, we are reaching ther |
Okay, assuming the tests pass, this is the version I'm sending for review. |
It seems test_ssl on macOS failed, but the other test failures have been resolved. Is that test flaky? |
Given the nature of this change and the fact that the error says:
I would say is unrelated. I have restarted manually the tests. |
🤖 New build scheduled with the buildbot fleet by @pablogsal for commit b725a65 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
LGTM! Let's do a buildbot pass to make sure there are no reference leaks. |
Seems we are missing something because some of the buildbots are crashing with segmentation faults. For instance: https://buildbot.python.org/all/#/builders/459/builds/69
The failures seem to be in test_inspect and test_zipfile |
Hm. I think this may happen when |
The problem was that sometimes a hint of -1 could be set, meaning the dict lookup failed. My code mistook that for a slot offset. The fix is simple, because slot offsets can never be 0, so ~offset can never be -1. I also cleaned up some comments and a variable name.
Here's the fix. @pablogsal how do I trigger a buildbot run? I can't find that in the devguide. |
You can add the "run with buildbots" label to the PR and the checks should start appearing at the bottom together with Travis and the other CI. |
🤖 New build scheduled with the buildbot fleet by @pablogsal for commit 4c2eb69 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
🤖 New build scheduled with the buildbot fleet by @gvanrossum for commit 17c8a95 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
// Hint >= 0 is a dict index; hint < 0 is an inverted slot index. | ||
if (la->hint < 0) { | ||
/* Even faster path -- slot hint */ | ||
// Hint >= 0 is a dict index; hint == -1 is a dict miss. |
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.
Oh, right! How did I miss that on review :/
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.
Same way I missed it writing the code. :-(
This code is hairy.
Python/ceval.c
Outdated
if (la->hint < 0) { | ||
/* Even faster path -- slot hint */ | ||
// Hint >= 0 is a dict index; hint == -1 is a dict miss. | ||
// Hint < -1 is an inverted slot offset (offsets are never 0). |
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.
Maybe clarify that slot offsets are always greater than 1?
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 have a comment ready to push:
// Hint >= 0 is a dict index; hint == -1 is a dict miss.
// Hint < -1 is an inverted slot offset: offset is strictly > 0,
// so ~offset is strictly < -1 (assuming 2's complement).
Let me know if you still want improvement.
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.
looks good to me
Looks like only 2 buildbots failed.
This seems a better result than before. |
I realized there's another optimization for this case. The code always starts with Is that worth exploring? It might be hard to prove there's no slowdown for the paths that do need the name. I could put this off to another PR -- if slots become more popular because of this PR we can add it later. :-) |
I’m just going to land this if there are no objections by tonight.
|
@gvanrossum: Please replace |
This is a modification of the
LOAD_ATTR
inline cache that landed a few months ago (PR 22803).The design overloads the
hint
field: if it is negative, it indicates a slot. Slots are created using__slots__
, but some builtin types that usePyMemberDescrObject
descriptors (with the type set toT_OBJECT_EX
) will also benefit.I've tried to keep the code style similar to the existing
LOAD_ATTR
cache (happy path first) but I had to make some compromises, e.g. the cache initialization code can no longer skip everything iftp_dictoffset
is zero (since it will be zero for classes with only slots).https://bugs.python.org/issue42927