bpo-38858: Small integer per interpreter#17315
Conversation
|
Example: The subinterpreter and the main interpreter don't have the same small integer singletons for numbers 1 and 2. |
Sorry, something went wrong.
That's a temporary solution which I consider as an acceptable compromise. Small integer singletons are not really part of the Python semantics. It's more the opposite, we advice to not use "is" operator to compare numbers. That's why Python starts to emit such SyntaxWarning: |
Sorry, something went wrong.
|
I rebased my PR to fix a confict. |
Sorry, something went wrong.
|
Should I run a benchmark? If yes, which kind of benchmark? |
Sorry, something went wrong.
ericsnowcurrently
left a comment
There was a problem hiding this comment.
mostly LGTM
Also, would it make sense to add any tests for this? I'm not sure it would add much.
Sorry, something went wrong.
|
When you're done making the requested changes, leave the comment: |
Sorry, something went wrong.
|
benchmark? Certainly the normal suite. On top of that, it might be nice to see a "worst-case" benchmark: code that heavily exercises the code paths that have calls to |
Sorry, something went wrong.
Here you have. In short, I see no performance regression (maybe speedups, but I'm not sure about these ones :-p). pyperformance benchmark results, ignoring differences smaller than 1%: pyperformance benchmark results, ignoring differences smaller than 1%: |
Sorry, something went wrong.
Each Python subinterpreter now has its own "small integer singletons": numbers in [-5; 257] range. It is no longer possible to change the number of small integers at build time by overriding NSMALLNEGINTS and NSMALLPOSINTS macros: macros should now be modified manually in pycore_pystate.h header file. For now, continue to share _PyLong_Zero and _PyLong_One singletons between all subinterpreters.
I would prefer until we get ride of _PyLong_Zero and _PyLong_One before going up to unit tests. Right now, you may get the subinterpreter singletons, or the main interpreter singletons depending on which function is called... This PR is a small step towards more isolated subinterpreters. It doesn't solve all issues at once ;-) |
Sorry, something went wrong.
|
As I wrote, I know that this change is not complete nor perfect. It's a small step towards better isolated subinterpreters. I chose to not document the backward incompatible change in What's New in Python 3.9, but only in the Changelog. IMHO it's enough, since it's really an obscure low-level feature (number of small integer singletons). |
Sorry, something went wrong.
|
Thanks for the review @ericsnowcurrently. I hope that I addressed most of your remarks ;-) |
Sorry, something went wrong.
Each Python subinterpreter now has its own "small integer singletons": numbers in [-5; 257] range. It is no longer possible to change the number of small integers at build time by overriding NSMALLNEGINTS and NSMALLPOSINTS macros: macros should now be modified manually in pycore_pystate.h header file. For now, continue to share _PyLong_Zero and _PyLong_One singletons between all subinterpreters.
Each Python subinterpreter now has its own "small integer
singletons": numbers in [-5; 257] range.
For now, continue to share _PyLong_Zero and _PyLong_One singletons
between all subinterpreters.
It is no longer possible to change the number of small integers at
build time by overriden macros: pycore_pystate.h macros should now be
modified manually.
https://bugs.python.org/issue38858