This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Antony.Lee, rhettinger, scoder, steven.daprano
Date 2018-02-25.17:30:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1519579835.73.0.467229070634.issue32945@psf.upfronthosting.co.za>
In-reply-to
Content
[Antony Lee]
> so both cases are much more similar -- superficially, at least.

Try disassembling the inner code object as well -- that is where the work gets done and the list comprehension can take advantage of the LIST_APPEND opcode (rather than passing data to list_extend through an iterator which has more overhead).

[Stefan Behnel]
> The difference is that comprehensions are generally more efficient than generators, simply because they are more specialised.

Yes, that is most succinct description of why would expect a difference.

[Steven D'Aprano]
> So I don't think this is a bug, and I don't think there's any room to optimize the generator comprehension case.

I concur.

[Antony Lee]
> Feel free to close the issue if that's not the forum for this discussion, but I'm still baffled by what's happening.

Yes, this discussion is more suited to a StackOverflow entry where people commonly ask about why Python behaves as it does.  The bug tracker is more suited to known regressions or provable optimizations.  (One forum is for "I'm baffled" and the other is for "I have an improvement").

Marking this a closed.  If some demonstrable optimization is found, feel free to reopen.
History
Date User Action Args
2018-02-25 17:30:35rhettingersetrecipients: + rhettinger, scoder, steven.daprano, Antony.Lee
2018-02-25 17:30:35rhettingersetmessageid: <1519579835.73.0.467229070634.issue32945@psf.upfronthosting.co.za>
2018-02-25 17:30:35rhettingerlinkissue32945 messages
2018-02-25 17:30:35rhettingercreate