Python and the need for speed

Gregory Ewing greg.ewing at canterbury.ac.nz
Thu Apr 13 02:19:24 EDT 2017


bart4858 at gmail.com wrote:
> (Although I think Python would have difficulty in turning x+=1 into a
> single opcode, if using normal object references and a shared object model.)

The ADD_ONE opcode would have to be defined to have the same
effect as the sequence emitted for x+=1, including all the
dynamic lookups, so the only speed advantage would be eliminating
a few trips around the bytecode fetch-decode-execute loop.
Which could still be worthwhile, if experience with the wordcode
interpreter is anything to go by.

There was also a project that attempted to find frequently
used sequences of opcodes and create specialised opcodes for
them, which reportedly had some success as well.

The logic behind these approaches is that unpredictable
branches, such as the opcode switch in the ceval loop, are
expensive on modern architectures, so eliminating as many of
them as possible can be a win.

-- 
Greg



More information about the Python-list mailing list