(original) (raw)

Thanks, Nick -- that's interesting. I just saw the extra JUMP\_FORWARD and JUMP\_ABSOLUTE instructions on my commute home (I guess those are something Python 3.x optimizes away).

VERY strangely, on Windows Python 2.7 is faster! Comparing 64-bit Python 2.7.12 against Python 3.5.3 on my Windows 10 laptop:

\* Python 2.7.12: 4.088s
\* Python 3.5.3: 5.792s

I'm pretty sure MSVC/Windows doesn't support computed gotos, but that doesn't explain why 3.5 is so much faster than 2.7 on Mac. I have yet to try it on Linux.

-Ben

On Tue, Jul 18, 2017 at 9:35 PM, Nick Coghlan <ncoghlan@gmail.com> wrote:
On 19 July 2017 at 02:18, Antoine Pitrou <solipsis@pitrou.net> wrote:
\> On Tue, 18 Jul 2017 12:03:36 -0400
\> Ben Hoyt <benhoyt@gmail.com> wrote:
>> The program is a pentomino puzzle solver, and it works via code generation,
\>> generating a ton of nested "if" statements, so I believe it's exercising
\>> the Python bytecode interpreter heavily.
\>
\> A first step would be to see if the generated bytecode has changed
\> substantially.

Scanning over them, the Python 2.7 bytecode appears to have many more
JUMP\_FORWARD and JUMP\_ABSOLUTE opcodes than appear in the 3.6 version
(I didn't dump them into a Counter instance to tally them properly
though, since 2.7's dis module is missing the structured opcode
iteration APIs).

With the shift to wordcode, the overall size of the bytecode is also
significantly \*smaller\*:

\>>> len(co.co\_consts\[0\].co\_code) # 2.7
14427

\>>> len(co.co\_consts\[0\].co\_code) # 3.6
11850

However, I'm not aware of any Python profilers that currently offer
opcode level profiling - the closest would probably be VMProf's JIT
profiling, and that aspect of VMProf is currently PyPy specific
(although could presumably be extended to CPython 3.6+ by way of the
opcode evaluation hook).

Cheers,
Nick.

\--
Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/benhoyt%40gmail.com