Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
GH-125837: SplitLOAD_CONST into three.#125972
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
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
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.
picnixz commentedOct 25, 2024
I think the range is -5 -> 256 (included) right? (at least _PyLong_SMALL_INTS works that way, but maybe 256 should be excluded even though it's stored in the _PyLong_SMALL_INTS). |
markshannon commentedOct 25, 2024
I want We can always add -5,-4,-3,-2 and -1 to |
markshannon commentedOct 25, 2024
Performance for tier 1 appears to be about 0.5% faster. Stats show the following fraction of constants loaded:
With a reduction in increfs of immortal objects of about 20%. |
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.
Uh oh!
There was an error while loading.Please reload this page.
Misc/NEWS.d/next/Core_and_Builtins/2024-10-25-15-56-14.gh-issue-125837.KlCdgD.rstShow resolvedHide resolved
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.
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.
Python/flowgraph.c Outdated
| for (inti=0;i<b->b_iused;i++) { | ||
| if (OPCODE_HAS_CONST(b->b_instr[i].i_opcode)) { | ||
| intopcode=b->b_instr[i].i_opcode; | ||
| if (OPCODE_HAS_CONST(opcode)&&opcode!=LOAD_SMALL_INT) { |
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.
hasconst is defined in thedis docs as "Sequence of bytecodes that access a constant". I think it will make more sense if we clarify that it means "access a constant fromco_consts" and then removeLOAD_SMALL_INT fromhasconst andOPCODE_HAS_CONST.
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.
That makes sense.LOAD_COMMON_CONST is not inhasconst.
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 it's worth testing whether creating integers within therange(256) will not affectco_consts?
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 want to go overboard on testing internal details of the bytecode compiler.LOAD_CONST with a smallint is still correct, just a bit less efficient thanLOAD_SMALL_INT.
We already have plenty of tests intest_dis that test this
Uh oh!
There was an error while loading.Please reload this page.
faa3272 intopython:mainUh oh!
There was an error while loading.Please reload this page.
* Add LOAD_CONST_IMMORTAL opcode* Add LOAD_SMALL_INT opcode* Remove RETURN_CONST opcode
* Add LOAD_CONST_IMMORTAL opcode* Add LOAD_SMALL_INT opcode* Remove RETURN_CONST opcode
Uh oh!
There was an error while loading.Please reload this page.
Splits
LOAD_CONSTinto three instructionsLOAD_INTfor ints inrange(256). Avoids the need for a space in theco_conststuple and avoids an increfLOAD_CONST_IMMORTALfor other immortal objects. Avoids an increfLOAD_CONSTfor the remaining constantsRETURN_VALUEandRETURN_CONST#125837📚 Documentation preview 📚:https://cpython-previews--125972.org.readthedocs.build/