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
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com