[Python-Dev] Rewrite @contextlib.contextmanager in C (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Tue Aug 9 09:30:25 EDT 2016


On 9 August 2016 at 23:26, Nick Coghlan <ncoghlan at gmail.com> wrote:

On 9 August 2016 at 06:18, Guido van Rossum <guido at python.org> wrote:

I think Nick would be interested in understanding why this is the case. What does the decorator do that could be so expensive?

Reviewing https://hg.python.org/cpython/file/default/Lib/contextlib.py#l57, Chris's analysis seems plausible to me

Sorry Wolfgang - I missed that Chris was expanding on a comparison you initially made!

Either way, I agree that aspect does make up the bulk of the difference in speed, so moving to C likely wouldn't help much. However, the speed difference relative to the simpler warppers is far less defensible - I think there are some opportunities for improvement there, especially around moving introspection work out of _GeneratorContextManager.init and into the contextmanager decorator itself.

Cheers, Nick.

-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160809/82173b1a/attachment.html>



More information about the Python-Dev mailing list