Author eltoder
Recipients eltoder
Date 2011-03-11.00:55:58
SpamBayes Score 1.52038e-07
Marked as misclassified No
Message-id <1299804959.52.0.82978036846.issue11462@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2011-03-11 00:55:59eltodersetrecipients: + eltoder
2011-03-11 00:55:59eltodersetmessageid: <1299804959.52.0.82978036846.issue11462@psf.upfronthosting.co.za>
2011-03-11 00:55:58eltoderlinkissue11462 messages
2011-03-11 00:55:58eltodercreate