Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
4a3cc9f0
Commit
4a3cc9f0
authored
Feb 08, 2016
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid allocating a closure in BaseServer.do_handle; reduces overhead by ~20% and is more debuggable
parent
c75efbec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
9 deletions
+20
-9
gevent/baseserver.py
gevent/baseserver.py
+20
-9
No files found.
gevent/baseserver.py
View file @
4a3cc9f0
...
...
@@ -11,6 +11,22 @@ from gevent.hub import string_types, integer_types, get_hub, xrange
__all__
=
[
'BaseServer'
]
# We define a helper function to handle closing the socket in
# do_handle; We'd like to bind it to a kwarg to avoid *any* lookups at
# all, but that's incompatible with the calling convention of
# do_handle. On CPython, this is ~20% faster than creating and calling
# a closure and ~10% faster than using a @staticmethod. (In theory, we
# could create a closure only once in set_handle, to wrap self._handle,
# but this is safer from a backwards compat standpoint.)
# we also avoid unpacking the *args tuple when calling/spawning this object
# for a tiny improvement (benchmark shows a wash)
def
_handle_and_close_when_done
(
handle
,
close
,
args_tuple
):
try
:
return
handle
(
*
args_tuple
)
finally
:
close
(
*
args_tuple
)
class
BaseServer
(
object
):
"""
An abstract base class that implements some common functionality for the servers in gevent.
...
...
@@ -147,20 +163,15 @@ class BaseServer(object):
def
do_handle
(
self
,
*
args
):
spawn
=
self
.
_spawn
handle
=
self
.
_handle
def
_close_when_done
(
*
args
):
try
:
return
handle
(
*
args
)
finally
:
self
.
do_close
(
*
args
)
close
=
self
.
do_close
try
:
if
spawn
is
None
:
_
close_when_done
(
*
args
)
_
handle_and_close_when_done
(
handle
,
close
,
args
)
else
:
spawn
(
_
close_when_done
,
*
args
)
spawn
(
_
handle_and_close_when_done
,
handle
,
close
,
args
)
except
:
self
.
do_
close
(
*
args
)
close
(
*
args
)
raise
def
do_close
(
self
,
*
args
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment