A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2012-August/121296.html below:

[Python-Dev] AST optimizer implemented in Python

[Python-Dev] AST optimizer implemented in PythonVictor Stinner victor.stinner at gmail.com
Sun Aug 12 03:17:54 CEST 2012
>> Other idea to improve this optimizer:
>>  - move invariant out of loops. Example: "x=[]; for i in range(10):
>> x.append(i)" => "x=[]; x_append=x.append; for i in range(10):
>> x_append(i)". Require to infer the type of variables.
>
> But this is risky. It's theoretically possible for x.append to replace
> itself.

For this specific example, x.append cannot be modified: it raises
AttributeError('list' object attribute 'append' is read-only).

The idea would be to allow the developer to specify explicitly what he
wants to optimize. I'm using a configuration class with a list of what
can be optimized (ex: len(int)), but it can be changed to something
different later.

It must be configurable to be able to specify: "this specific variable
is constant in my project"..

> Perhaps the best way is to hide potentially-risky optimizations behind
> command-line options? The default mode could be to do every change
> that's guaranteed not to affect execution, and everything else is an
> extra (like French, music, and washing).

I don't care of integration into Python yet (but it would be nice to
prepare such feature in Python 3.4). It can be a third party module,
something like:

   import ast_optimizer
   ast_optimizer.hack_import_machinery()
   ast_optimizer.constants.add('application.DEBUG')

(added on the top of your main script)

Victor
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4