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 ?










share|improve this question



























    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 ?










    share|improve this question

























      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 ?










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 20:52









      jonrsharpe

      76k1098204




      76k1098204










      asked Nov 10 at 20:46









      AmjadHD

      42




      42






















          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





          share|improve this answer




















          • 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










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          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

























          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





          share|improve this answer




















          • 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














          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





          share|improve this answer




















          • 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












          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





          share|improve this answer












          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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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
















          • 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

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          政党