python new AST optimizer
up vote
1
down vote
favorite
from python 3.7 what's new
Constant folding has been moved from the peephole optimizer to the new AST optimizer, which is able perform optimizations more consistently
what optimizations is this new AST optimizer able to perform and how is it different from the peephole optimizer ?
python python-3.x optimization python-internals
add a comment |
up vote
1
down vote
favorite
from python 3.7 what's new
Constant folding has been moved from the peephole optimizer to the new AST optimizer, which is able perform optimizations more consistently
what optimizations is this new AST optimizer able to perform and how is it different from the peephole optimizer ?
python python-3.x optimization python-internals
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
from python 3.7 what's new
Constant folding has been moved from the peephole optimizer to the new AST optimizer, which is able perform optimizations more consistently
what optimizations is this new AST optimizer able to perform and how is it different from the peephole optimizer ?
python python-3.x optimization python-internals
from python 3.7 what's new
Constant folding has been moved from the peephole optimizer to the new AST optimizer, which is able perform optimizations more consistently
what optimizations is this new AST optimizer able to perform and how is it different from the peephole optimizer ?
python python-3.x optimization python-internals
python python-3.x optimization python-internals
edited Nov 10 at 20:52
jonrsharpe
76k1098203
76k1098203
asked Nov 10 at 20:46
AmjadHD
42
42
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
If you read the associated bug reports, they contain most of the details. Most of it is pretty dry stuff that doesn't really matter to most code, which is why they don't include the details in "What's New".
Examples where it matters are usually strange cases that are rarely encountered, but that the peephole optimizer (which couldn't do higher level evaluation, just simple byte code rewrites in place) couldn't handle, e.g. on Python 3.6:
>>> import dis
>>> dis.dis('if True: pass') # Recognizes simple case and omits whole block
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
>>> dis.dis('if True and 1: pass') # Can't recognize more complex case
1 0 LOAD_CONST 0 (True)
2 POP_JUMP_IF_FALSE 8
4 LOAD_CONST 1 (1)
6 POP_JUMP_IF_FALSE 8
>> 8 LOAD_CONST 2 (None)
10 RETURN_VALUE
whereas on 3.7:
>>> import dis
>>> dis.dis('if True: pass') # Recognizes simple case and omits whole block
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
>>> dis.dis('if True and 1: pass') # Handles more complex case too
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
well that's not interesting, can/will it do more optimizations such as function's inlining or loop unrolling ?, function inlining will be a major addition.
– AmjadHD
Nov 10 at 22:23
@AmjadHD: Nope. CPython does not and will not (in the foreseeable future) be doing any aggressive optimizations of that sort. Like I said, there is a reason this didn't get top billing in the new release; it's basically just ensuring the really basic optimizations it applied are applied more consistently.
– ShadowRanger
Nov 11 at 5:16
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
If you read the associated bug reports, they contain most of the details. Most of it is pretty dry stuff that doesn't really matter to most code, which is why they don't include the details in "What's New".
Examples where it matters are usually strange cases that are rarely encountered, but that the peephole optimizer (which couldn't do higher level evaluation, just simple byte code rewrites in place) couldn't handle, e.g. on Python 3.6:
>>> import dis
>>> dis.dis('if True: pass') # Recognizes simple case and omits whole block
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
>>> dis.dis('if True and 1: pass') # Can't recognize more complex case
1 0 LOAD_CONST 0 (True)
2 POP_JUMP_IF_FALSE 8
4 LOAD_CONST 1 (1)
6 POP_JUMP_IF_FALSE 8
>> 8 LOAD_CONST 2 (None)
10 RETURN_VALUE
whereas on 3.7:
>>> import dis
>>> dis.dis('if True: pass') # Recognizes simple case and omits whole block
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
>>> dis.dis('if True and 1: pass') # Handles more complex case too
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
well that's not interesting, can/will it do more optimizations such as function's inlining or loop unrolling ?, function inlining will be a major addition.
– AmjadHD
Nov 10 at 22:23
@AmjadHD: Nope. CPython does not and will not (in the foreseeable future) be doing any aggressive optimizations of that sort. Like I said, there is a reason this didn't get top billing in the new release; it's basically just ensuring the really basic optimizations it applied are applied more consistently.
– ShadowRanger
Nov 11 at 5:16
add a comment |
up vote
2
down vote
If you read the associated bug reports, they contain most of the details. Most of it is pretty dry stuff that doesn't really matter to most code, which is why they don't include the details in "What's New".
Examples where it matters are usually strange cases that are rarely encountered, but that the peephole optimizer (which couldn't do higher level evaluation, just simple byte code rewrites in place) couldn't handle, e.g. on Python 3.6:
>>> import dis
>>> dis.dis('if True: pass') # Recognizes simple case and omits whole block
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
>>> dis.dis('if True and 1: pass') # Can't recognize more complex case
1 0 LOAD_CONST 0 (True)
2 POP_JUMP_IF_FALSE 8
4 LOAD_CONST 1 (1)
6 POP_JUMP_IF_FALSE 8
>> 8 LOAD_CONST 2 (None)
10 RETURN_VALUE
whereas on 3.7:
>>> import dis
>>> dis.dis('if True: pass') # Recognizes simple case and omits whole block
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
>>> dis.dis('if True and 1: pass') # Handles more complex case too
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
well that's not interesting, can/will it do more optimizations such as function's inlining or loop unrolling ?, function inlining will be a major addition.
– AmjadHD
Nov 10 at 22:23
@AmjadHD: Nope. CPython does not and will not (in the foreseeable future) be doing any aggressive optimizations of that sort. Like I said, there is a reason this didn't get top billing in the new release; it's basically just ensuring the really basic optimizations it applied are applied more consistently.
– ShadowRanger
Nov 11 at 5:16
add a comment |
up vote
2
down vote
up vote
2
down vote
If you read the associated bug reports, they contain most of the details. Most of it is pretty dry stuff that doesn't really matter to most code, which is why they don't include the details in "What's New".
Examples where it matters are usually strange cases that are rarely encountered, but that the peephole optimizer (which couldn't do higher level evaluation, just simple byte code rewrites in place) couldn't handle, e.g. on Python 3.6:
>>> import dis
>>> dis.dis('if True: pass') # Recognizes simple case and omits whole block
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
>>> dis.dis('if True and 1: pass') # Can't recognize more complex case
1 0 LOAD_CONST 0 (True)
2 POP_JUMP_IF_FALSE 8
4 LOAD_CONST 1 (1)
6 POP_JUMP_IF_FALSE 8
>> 8 LOAD_CONST 2 (None)
10 RETURN_VALUE
whereas on 3.7:
>>> import dis
>>> dis.dis('if True: pass') # Recognizes simple case and omits whole block
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
>>> dis.dis('if True and 1: pass') # Handles more complex case too
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
If you read the associated bug reports, they contain most of the details. Most of it is pretty dry stuff that doesn't really matter to most code, which is why they don't include the details in "What's New".
Examples where it matters are usually strange cases that are rarely encountered, but that the peephole optimizer (which couldn't do higher level evaluation, just simple byte code rewrites in place) couldn't handle, e.g. on Python 3.6:
>>> import dis
>>> dis.dis('if True: pass') # Recognizes simple case and omits whole block
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
>>> dis.dis('if True and 1: pass') # Can't recognize more complex case
1 0 LOAD_CONST 0 (True)
2 POP_JUMP_IF_FALSE 8
4 LOAD_CONST 1 (1)
6 POP_JUMP_IF_FALSE 8
>> 8 LOAD_CONST 2 (None)
10 RETURN_VALUE
whereas on 3.7:
>>> import dis
>>> dis.dis('if True: pass') # Recognizes simple case and omits whole block
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
>>> dis.dis('if True and 1: pass') # Handles more complex case too
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
answered Nov 10 at 21:46
ShadowRanger
55.7k44790
55.7k44790
well that's not interesting, can/will it do more optimizations such as function's inlining or loop unrolling ?, function inlining will be a major addition.
– AmjadHD
Nov 10 at 22:23
@AmjadHD: Nope. CPython does not and will not (in the foreseeable future) be doing any aggressive optimizations of that sort. Like I said, there is a reason this didn't get top billing in the new release; it's basically just ensuring the really basic optimizations it applied are applied more consistently.
– ShadowRanger
Nov 11 at 5:16
add a comment |
well that's not interesting, can/will it do more optimizations such as function's inlining or loop unrolling ?, function inlining will be a major addition.
– AmjadHD
Nov 10 at 22:23
@AmjadHD: Nope. CPython does not and will not (in the foreseeable future) be doing any aggressive optimizations of that sort. Like I said, there is a reason this didn't get top billing in the new release; it's basically just ensuring the really basic optimizations it applied are applied more consistently.
– ShadowRanger
Nov 11 at 5:16
well that's not interesting, can/will it do more optimizations such as function's inlining or loop unrolling ?, function inlining will be a major addition.
– AmjadHD
Nov 10 at 22:23
well that's not interesting, can/will it do more optimizations such as function's inlining or loop unrolling ?, function inlining will be a major addition.
– AmjadHD
Nov 10 at 22:23
@AmjadHD: Nope. CPython does not and will not (in the foreseeable future) be doing any aggressive optimizations of that sort. Like I said, there is a reason this didn't get top billing in the new release; it's basically just ensuring the really basic optimizations it applied are applied more consistently.
– ShadowRanger
Nov 11 at 5:16
@AmjadHD: Nope. CPython does not and will not (in the foreseeable future) be doing any aggressive optimizations of that sort. Like I said, there is a reason this didn't get top billing in the new release; it's basically just ensuring the really basic optimizations it applied are applied more consistently.
– ShadowRanger
Nov 11 at 5:16
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243242%2fpython-new-ast-optimizer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown