This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eltoder
Recipients eltoder
Date 2011-03-11.00:55:58
SpamBayes Score 1.52038e-07
Marked as misclassified No
Message-id <>
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:59eltodersetrecipients: + eltoder
2011-03-11 00:55:59eltodersetmessageid: <>
2011-03-11 00:55:58eltoderlinkissue11462 messages
2011-03-11 00:55:58eltodercreate