Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
#93229 introduced a regression in how aggressively we quicken somefor loops. Minimal example:
deff(x:bool)->None:foriinrange(1_000_000):ifx:pass
f(True) will quicken this code, butf(False) will not, even though both contain the same number of back edges. The issue is that we only quicken onunconditional backwards jumps, not on conditional ones.
We've known about this limitation for some time, in particular with regard towhile loops. Since we check the loop condition at the bottom ofwhile loops, one call is not enough to quickenw:
defw()->None:i=0whilei<1_000_000:i+=1
@markshannon has expressed a preference for having all branches be forward (i.e. replacing backwardPOP_JUMP_IF_FALSE(x) instructions withPOP_JUMP_FORWARD_IF_TRUE(1); JUMP_BACKWARD(x) in the assembler).@iritkatriel believes that this shouldn't be too difficult, based on recent assembler rewrites.