Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance by using Python C API to enter/exit context #627

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions uvloop/loop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,27 @@ cdef inline socket_dec_io_ref(sock):


cdef inline run_in_context(context, method):
# This method is internally used to workaround a reference issue that in
# certain circumstances, inlined context.run() will not hold a reference to
# the given method instance, which - if deallocated - will cause segfault.
# See also: edgedb/edgedb#2222
Py_INCREF(method)
Context_Enter(context)
try:
return context.run(method)
return method()
finally:
Py_DECREF(method)
Context_Exit(context)


cdef inline run_in_context1(context, method, arg):
Py_INCREF(method)
Context_Enter(context)
try:
return context.run(method, arg)
return method(arg)
finally:
Py_DECREF(method)
Context_Exit(context)


cdef inline run_in_context2(context, method, arg1, arg2):
Py_INCREF(method)
Context_Enter(context)
try:
return context.run(method, arg1, arg2)
return method(arg1, arg2)
finally:
Py_DECREF(method)
Context_Exit(context)


# Used for deprecation and removal of `loop.create_datagram_endpoint()`'s
Expand Down
Loading