Repository navigation
Emit slices as constants in the bytecode compiler #125063
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancementperformancePerformance or resource usagePerformance or resource usage
on Oct 7, 2024 Shouldn't this be closed now?
Shouldn't this be closed now?
Yep -- sorry, I forgot that step.
Reacted by Nice ZombiesHi @mdboom,
This is missing a documentation update, since marshal docs have a list of the types thatpyccan handle.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
"abc"[:1]to"a"isn't too relevant).I quickly tried moving it, and tests pass, but I don't know if I'm missing something: main...encukou:cpython:const_slice
Reacted by Nice Zombieshis is missing a documentation update, since marshal docs have a list of the types that pyc can handle.
Thanks for pointing that out. I'll handle that part.
But, I wanted to ask: would it make sense to do the folding in AST, rather than in codegen?
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.
Reacted by Petr ViktorinBut, I wanted to ask: would it make sense to do the folding in AST, rather than in codegen?
Yes, I think this makes sense.
- added a commit that references this issue
on Nov 13, 2024
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_CONSTinstruction: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