◐ Shell
clean mode source ↗

Message 214934 - Python tracker

The redesigned peephole optimizer in PY3 improves constant folding. Limiting this would be a step back. Plus you can get the same behavior in PY2 if you first expand the power. For example:

    # using 2**30, for a 32-bit process

    def uncalled():
        x = b'x' * 1073741824

At issue is the design of fold_binops_on_constants in peephole.c:

http://hg.python.org/cpython/file/04f714765c13/Python/peephole.c#l138

Some LBYL may be helpful here. It could get the size and integer value of the two objects before evaluating the switch statement. Then use these values to skip certain operations, such as skipping PyNumber_Multiply in the case of BINARY_MULTIPLY.