-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Emit slices as constants in the bytecode compiler #125063
Comments
* Make slices marshallable * Emit slices as constants * Update Python/marshal.c Co-authored-by: Peter Bierma <[email protected]> * Refactor codegen_slice into two functions so it always has the same net effect * Fix for free-threaded builds * Simplify marshal loading of slices * Only return SUCCESS/ERROR from codegen_slice --------- Co-authored-by: Mark Shannon <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
Shouldn't this be closed now? |
Yep -- sorry, I forgot that step. |
…ython#125064) * Make slices marshallable * Emit slices as constants * Update Python/marshal.c Co-authored-by: Peter Bierma <[email protected]> * Refactor codegen_slice into two functions so it always has the same net effect * Fix for free-threaded builds * Simplify marshal loading of slices * Only return SUCCESS/ERROR from codegen_slice --------- Co-authored-by: Mark Shannon <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
Hi @mdboom, But, I wanted to ask: would it make sense to do the folding in AST, rather than in codegen? That seems like a more appropriate place, even though it probably won't help common code (e.g. folding I quickly tried moving it, and tests pass, but I don't know if I'm missing something: main...encukou:cpython:const_slice |
Thanks for pointing that out. I'll handle that part.
I don't know if I have enough historical to say which is better, it does seem like doing it earlier makes sense. I'd want a second opinion about whether it's the right thing to do, though (Cc: @iritkatriel?), and if so, you should submit your branch as a PR. |
Yes, I think this makes sense. |
Feature or enhancement
Proposal:
Constant slices are currently emitted as multiple bytecodes by the Python bytecode compiler.
For example,
x[:-2, 1:-1]
generates:Then tuples of slices are constant like this, this could instead be compiled down to a single
LOAD_CONST
instruction:According to @fberlakovich and Stefan Brunthaler's paper on Cross module quickening, this can have a significant impact on Numpy benchmarks.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: