[Python-Dev] AST optimizer implemented in Python (original) (raw)
Stefan Behnel stefan_ml at behnel.de
Sun Aug 12 06:42:25 CEST 2012
- Previous message: [Python-Dev] AST optimizer implemented in Python
- Next message: [Python-Dev] AST optimizer implemented in Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Chris Angelico, 12.08.2012 01:22:
Other idea to improve this optimizer: - move invariant out of loops. Example: "x=[]; for i in range(10): x.append(i)" => "x=[]; xappend=x.append; for i in range(10): xappend(i)". Require to infer the type of variables. But this is risky. It's theoretically possible for x.append to replace itself. Sure it may not be a normal or common thing to do, but it's possible.
Not only that. It changes semantics. If x.append is not defined, the exception would now be raised outside of the loop, and the loop itself may have side-effects already. In fact, the mere lookup of x.append may have side effects as well ...
Stefan
- Previous message: [Python-Dev] AST optimizer implemented in Python
- Next message: [Python-Dev] AST optimizer implemented in Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]