Tiny optimization that replaces Replace STORE_FAST x LOAD_FAST x with DUP_TOP STORE_FAST x (for the same slot x). Targeted at quite common case: foo = self.foo if foo > 0: ... No regression, seems to do what it is supposed to do on several test cases. However, there is drawback: def f(x): y = x.y if y is not None: print y is disassembled as follows: 2 0 LOAD_FAST 0 (x) 3 LOAD_ATTR 0 (y) 6 DUP_TOP 3 7 STORE_FAST 1 (y) 10 LOAD_CONST 0 (None) 13 COMPARE_OP 9 (is not) 16 JUMP_IF_FALSE 9 (to 28) 19 POP_TOP 4 20 LOAD_FAST 1 (y) 23 PRINT_ITEM 24 PRINT_NEWLINE 25 JUMP_FORWARD 1 (to 29) >> 28 POP_TOP >> 29 LOAD_CONST 0 (None) 32 RETURN_VALUE Note that STORE_FAST "migrated" to another line. I'm not sure how important that is.
I'll look at this one again. It was tried once and rejected for some reason that I've since forgotten (lack of measurable speed-up, interference with some other optimization, or some such).
This was previously rejected for two reasons. 1) It provided almost no measureable speed-up (the code for LOAD_FAST and DUP_TOP is substantially the same, the only real difference is the time to fetch the oparg). 2) The optimization typically crosses lines of source code, making it difficult to follow in a trace or disassembly.
History
Date
User
Action
Args
2022-04-11 14:56:25
admin
set
github: 45258
2008-05-31 04:52:59
rhettinger
set
status: open -> closedresolution: rejectedmessages: +