A RetroSearch Logo

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

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20160809/d1037fdc/attachment-0001.html below:

<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 9 August 2016 at 06:18, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I think Nick would be interested in understanding why this is the case. What does the decorator do that could be so expensive?<br></div></blockquote><div><br></div><div>Reviewing <a href="https://hg.python.org/cpython/file/default/Lib/contextlib.py#l57">https://hg.python.org/cpython/file/default/Lib/contextlib.py#l57</a>, Chris's analysis seems plausible to me: most of the cost is going to be in the fact that instead of a single function call for __exit__ and __enter__, we have a function call *and* a generator frame resumption, and in the case of __exit__, the expected flow includes catching StopIteration. The object creation is also marginally more expensive, since it's indirect through a factory function rather than calling the type directly.<br><br></div><div>There's also currently some introspection of "func" being done in __init__ as a result of issue #19330 that should probably be moved out to the contextmanager decorator and passed in from the closure as a separate argument rather than being figured out on each call to _GeneratorContextManager.__init__.<br><br></div><div>So I don't see any obvious reason we shouldn't be able to get the standard library version at least to a similar level of performance to Chris's simpler alternatives. There are also some potential object allocation efficiencies we could consider, like using __slots__ to eliminate the __dict__ allocation (that does have backwards compatibility implications, but may be worth it if it buys a non-trivial speed improvement).<br><br>Beyond that, while I think a C accelerator may be worth trying, I'm not sure how much it will actually gain us, as it seems plausible that a function call + generator frame resumption will inherently take twice as long as just doing a function call.<br></div><br></div><div class="gmail_quote">Regards,<br></div><div class="gmail_quote">Nick.<br><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Nick Coghlan   |   <a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>   |   Brisbane, Australia</div>
</div></div>

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