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 vstinner
Recipients serhiy.storchaka, vstinner
Date 2015-12-09.08:24:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1449649487.71.0.481163221957.issue25828@psf.upfronthosting.co.za>
In-reply-to
Content
FYI.

> Peephole optimizer of Python 2.7 (...) only optimizes 2**100, but not 2**(2**100).

This optimizer is dummy, it's only able to replace "LOAD_CONST x; LOAD_CONST y; OPERATION" with the result, whereas the optimizer replaces the bytecode with "NOP; NOP; NOP; NOP; LOAD_CONST z".

So "LOAD_CONST x; LOAD_CONST y; LOAD_CONST z; OPERATION1; OPERATION2" cannot be optimized. But it's enough to optimize 1+2+3 or 1*2*3 for example.

Python 3 peephole optimize does better thanks to a better design:
---
changeset:   68375:14205d0fee45
user:        Antoine Pitrou <solipsis@pitrou.net>
date:        Fri Mar 11 17:27:02 2011 +0100
files:       Lib/test/test_peepholer.py Misc/NEWS Python/peephole.c
description:
Issue #11244: The peephole optimizer is now able to constant-fold
arbitrarily complex expressions.  This also fixes a 3.2 regression where
operations involving negative numbers were not constant-folded.
---

It uses a stack for constants, so it's able to optimize more cases.
History
Date User Action Args
2015-12-09 08:24:47vstinnersetrecipients: + vstinner, serhiy.storchaka
2015-12-09 08:24:47vstinnersetmessageid: <1449649487.71.0.481163221957.issue25828@psf.upfronthosting.co.za>
2015-12-09 08:24:47vstinnerlinkissue25828 messages
2015-12-09 08:24:47vstinnercreate