[Python-Dev] Micro-optimizations by adding special-case bytecodes? (original) (raw)
Stephane Wirtel stephane at wirtel.be
Wed May 24 14:12:15 EDT 2017
- Previous message (by thread): [Python-Dev] Micro-optimizations by adding special-case bytecodes?
- Next message (by thread): [Python-Dev] Micro-optimizations by adding special-case bytecodes?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
there is the Peephole for that, it's a small optimizer in the compiler.
On 05/24/2017 08:07 PM, Ben Hoyt wrote:
Hi folks,
I was looking at some
dis
output today, and I was wondering if anyone has investigated optimizing Python (slightly) by adding special-case bytecodes for common expressions or statements involving constants? For example, I (and, based on a quick grep of the stdlib, many others) write "x is None" and "x is not None" very often. Or "return True" or "return None" or "return 1" and things like that. These all expand into two bytecodes, which seems pretty non-optimal (LOADCONST + COMPAREOP or LOADCONST + RETURNVALUE). It seems we could get an easy speedup for these common cases by adding a peephole optimization and some new opcodes (maybe COMPAREISSMALLCONST and RETURNSMALLCONST for these cases). I'm not proposing to do this yet, as I'd need to benchmark to see how much of a gain (if any) it would amount to, but I'm just wondering if there's any previous work on this kind of thing. Or, if not, any other thoughts before I try it? Thanks, Ben
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/stephane%40wirtel.be
- Previous message (by thread): [Python-Dev] Micro-optimizations by adding special-case bytecodes?
- Next message (by thread): [Python-Dev] Micro-optimizations by adding special-case bytecodes?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]