A RetroSearch Logo

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

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2016-August/145790.html below:

[Python-Dev] Rewrite @contextlib.contextmanager in C

[Python-Dev] Rewrite @contextlib.contextmanager in C [Python-Dev] Rewrite @contextlib.contextmanager in CYury Selivanov yselivanov.ml at gmail.com
Mon Aug 8 16:38:51 EDT 2016
On 2016-08-08 4:18 PM, Guido van Rossum wrote:
> I think Nick would be interested in understanding why this is the 
> case. What does the decorator do that could be so expensive?

 From the looks of it it doesn't do anything special.  Although with 
@contextlib.contextmanager we have to instantiate a generator (the 
decorated one) and advance it in __enter__.  So it's an extra object 
instantiation + extra code in __enter__ and __exit__.  Anyways, Nick 
knows much more about that code.

Giampaolo, before experimenting with a C implementation, I suggest you 
to try to compile contextlib.py with Cython.  I'll be surprised if you 
can make it more than 30-40% faster.  And you won't get much faster than 
Cython when you code contextmanager in C by hand.

Also, we don't have slots for __enter__ and __exit__, so there is no way 
to avoid the attribute lookup.

Yury
More information about the Python-Dev mailing list

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