Message130537
Peephole optimizer performs constant folding, however
1) When it replaces operation with LOAD_CONST it always adds a new constant to co_consts, even if constant with the same value is already there. It also can add the same constant multiple times.
2) It does not remove constants that are no longer used after the operation was folded.
The result is that code object after folding has more constants that it needs and so uses more memory.
Attached are patches to address this. Patch for 1) comes in 2 versions. PlanA is simple (it only needs changes in peephole.c), but does linear searches through co_consts and duplicates some logic from compiler.c. PlanB needs changes in both peephole.c and compiler.c, but is free from such problems. I favour PlanB.
Patch for 2) can be applied on top of either A or B. |
|
Date |
User |
Action |
Args |
2011-03-11 00:55:59 | eltoder | set | recipients:
+ eltoder |
2011-03-11 00:55:59 | eltoder | set | messageid: <1299804959.52.0.82978036846.issue11462@psf.upfronthosting.co.za> |
2011-03-11 00:55:58 | eltoder | link | issue11462 messages |
2011-03-11 00:55:58 | eltoder | create | |
|