Message241626
There are a lot of optimizations that are being missed by only running a single pass of PyCode_Optimize. I originally started by trying to optimize for De Morgan's Laws in if tests; however, I realized that the issue actually went away if you run the optimizer twice. I imagine that this would provide a lot of other performance increases because some of the patterns don't show up until the optimizer has already run once. For example:
>>> def f(a, b):
... if not a and not b:
... return True
... return False
...
On default, this generates:
>>> dis(f)
2 0 LOAD_FAST 0 (a)
3 UNARY_NOT
4 POP_JUMP_IF_FALSE 18
7 LOAD_FAST 1 (b)
10 UNARY_NOT
11 POP_JUMP_IF_FALSE 18
3 14 LOAD_CONST 1 (True)
17 RETURN_VALUE
4 >> 18 LOAD_CONST 2 (False)
21 RETURN_VALUE
If we run the optimizer again, we can collapse some of the UNARY_NOT -> POP_JUMP_IF_FALSE back into POP_JUMP_IF_TRUE, like this:
>>> dis(f)
2 0 LOAD_FAST 0 (a)
3 POP_JUMP_IF_TRUE 16
6 LOAD_FAST 1 (b)
9 POP_JUMP_IF_TRUE 16
3 12 LOAD_CONST 1 (True)
15 RETURN_VALUE
4 >> 16 LOAD_CONST 2 (False)
19 RETURN_VALUE
Also, Python/importlib.h blew up in the diff; should this be included in the patch? |
|
Date |
User |
Action |
Args |
2015-04-20 09:09:20 | llllllllll | set | recipients:
+ llllllllll |
2015-04-20 09:09:20 | llllllllll | set | messageid: <1429520960.11.0.0723675041232.issue24014@psf.upfronthosting.co.za> |
2015-04-20 09:09:19 | llllllllll | link | issue24014 messages |
2015-04-20 09:09:19 | llllllllll | create | |
|