Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.4k
gh-127119: Faster check for small ints in long_dealloc#127620
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
markshannon left a comment
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.
This is technically not legal C.
Pointer comparisons between separately allocated blocks of memory are undefined.
Which is a shame, because this is clearly faster.
eendebakpt commentedDec 5, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Pointer comparisions are indeed not always well-defined. For reference: seehttps://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf, section 6.5.8.6, orhttps://www.gnu.org/software/c-intro-and-ref/manual/html_node/Pointer-Comparison.html. I updated the PR to use the immortality bit instead. (maybe there are some more places where we need to update documentation on the immortality bit) |
Uh oh!
There was an error while loading.Please reload this page.
| @@ -0,0 +1 @@ | |||
| Slightly optimize the:class:`int` deallocator. | |||
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 include the benchmarks results (it's a 4% improvement which is still noticable IMO). You should mention that it only concerns PGO builds as well.
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
… into small_int_immortal_v2
Uh oh!
There was an error while loading.Please reload this page.
eendebakpt commentedDec 5, 2024
Turns out the immortal bit was assumed to be zero in |
Uh oh!
There was an error while loading.Please reload this page.
chris-eibl commentedDec 7, 2024
@eduardo-elizondo already spotted that back then#102464 (comment) and created#103403, especially to target |
eendebakpt commentedDec 7, 2024
@chris-eibl Thanks for that little bit of history. @markshannon@eduardo-elizondo This PR is more or less identical to#103403 which has been closed. Unless you feel different about it now, I suggest we close this. |
chris-eibl commentedDec 8, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
But your microbenchmarks for the initial version seemed promising. The results of thepyperformance fleet would be interesting, too, since you had to touch I like that in your code the comment about Accidental De-Immortalizing is now exactly before In the previous version, I had to read carefully, especially because it starts with "This should never get called", which of course does not comment on the invocation of Every none-small-int will be deallocated, and for all of them we pay the price of I don't care much about |
markshannon left a comment
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.
A few very minor issues
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Objects/longobject.c Outdated
| _PyLong_ExactDealloc(PyObject*self) | ||
| { | ||
| assert(PyLong_CheckExact(self)); | ||
| #ifndefPy_GIL_DISABLED |
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 don't think we should excluding the no-gil build.
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.
You are right. According tohttps://peps.python.org/pep-0683/#stable-abi the no-gil implementation can work with older stable API extensions.
Objects/longobject.c Outdated
| _Py_FREELIST_FREE(ints,self,PyObject_Free); | ||
| return; | ||
| } | ||
| #ifndefPy_GIL_DISABLED |
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.
Likewise
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Mark Shannon <mark@hotpy.org>
eendebakpt commentedDec 23, 2024
@markshannon Adding the small int check for the free-threaded build uncovered a bug: we have to prevent copying the immortal bit when subclassing int. I addresed the bug in |
eendebakpt commentedJan 8, 2025
I have made the requested changes; please review again |
Thanks for making the requested changes! @markshannon: please review the changes made to this pull request. |
markshannon left a comment
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
a292216 intopython:mainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
long_deallocMicrobenchmark from#127120:
(benchmark is with PGO, without PGO I see no performance improvement)