[pypy-svn] r55648 - in pypy/dist/pypy/module: signal thread
arigo at codespeak.net
arigo at codespeak.net
Sat Jun 7 12:35:50 CEST 2008
Author: arigo
Date: Sat Jun 7 12:35:48 2008
New Revision: 55648
Modified:
pypy/dist/pypy/module/signal/interp_signal.py
pypy/dist/pypy/module/thread/threadlocals.py
Log:
Two small tweaks that reduce a lot the overhead of using threads
in a thread-aware pypy-c.
Modified: pypy/dist/pypy/module/signal/interp_signal.py
==============================================================================
--- pypy/dist/pypy/module/signal/interp_signal.py (original)
+++ pypy/dist/pypy/module/signal/interp_signal.py Sat Jun 7 12:35:48 2008
@@ -31,7 +31,9 @@
pypysig_ignore = external('pypysig_ignore', [rffi.INT], lltype.Void)
pypysig_default = external('pypysig_default', [rffi.INT], lltype.Void)
pypysig_setflag = external('pypysig_setflag', [rffi.INT], lltype.Void)
-pypysig_poll = external('pypysig_poll', [], rffi.INT)
+pypysig_poll = external('pypysig_poll', [], rffi.INT, threadsafe=False)
+# don't bother releasing the GIL around a call to pypysig_poll: it's
+# pointless and a performance issue
class CheckSignalAction(Action):
"""A repeatitive action at the space level, checking if the
Modified: pypy/dist/pypy/module/thread/threadlocals.py
==============================================================================
--- pypy/dist/pypy/module/thread/threadlocals.py (original)
+++ pypy/dist/pypy/module/thread/threadlocals.py Sat Jun 7 12:35:48 2008
@@ -9,10 +9,19 @@
def __init__(self):
self._valuedict = {} # {thread_ident: ExecutionContext()}
self._mainthreadident = 0
+ self._mostrecentkey = 0 # fast minicaching for the common case
+ self._mostrecentvalue = None # fast minicaching for the common case
def getvalue(self):
ident = thread.get_ident()
- return self._valuedict.get(ident, None)
+ if ident == self._mostrecentkey:
+ return self._mostrecentvalue
+ else:
+ value = self._valuedict.get(ident, None)
+ # slow path: update the minicache
+ self._mostrecentkey = ident
+ self._mostrecentvalue = value
+ return value
def setvalue(self, value):
ident = thread.get_ident()
@@ -25,6 +34,9 @@
del self._valuedict[ident]
except KeyError:
pass
+ # update the minicache to prevent it from containing an outdated value
+ self._mostrecentkey = ident
+ self._mostrecentvalue = value
def getmainthreadvalue(self):
ident = self._mainthreadident
More information about the Pypy-commit
mailing list