[issue4264] Patch: optimize code to use LIST_APPEND instead of calling list.append

David Turner report at bugs.python.org
Fri Nov 7 17:25:26 CET 2008


David Turner <novalis at novalis.org> added the comment:

> FWIW, I see exposing bytecodes as an anti-pattern that locks in a
> particular implementation in a way that makes it hard to change and 
> hard to port to other Python implementations.  The current bound 
> method approach works fine.  Don't really see enough payoff to 
> justify the extra code and maintenance.

Bytecodes aren't exposed at the language level -- just during
compilation.  As far as I know, other implementations don't use any of
the Python compiler mechanics, so there's no portability problem.  If
another compiler did use the Python AST, they could just compile the
Append node kind to a method call with no loss of speed or clarity.  Or
they could just not use this optimization, if we refactor the ast
optimizer as I propose to use the strategy pattern.

As for the payoff, microbenchmarks show a big win.  Also, appending to a
list is a fairly common pattern.  Our Plone-based codebase shows tens of
thousands of instances of append.

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4264>
_______________________________________


More information about the Python-bugs-list mailing list