[New-bugs-announce] [issue15124] _thread.LockType: Optimize lock deletion, acquisition of uncontested lock and release of lock.
Kristján Valur Jónsson
report at bugs.python.org
Thu Jun 21 16:11:40 CEST 2012
New submission from Kristján Valur Jónsson <kristjan at ccpgames.com>:
_thread.LockType contains code for sanity checking when the lock is released, and for unlocking it when it is deleted. Both operations involve actually try-lock operations that are costly. Use a flag on the log to keep track of its locking state instead.
Also, acquiring a lock now first tries a try-aqcuire without releasing the GIL, same as _thread.RLock(). This is done by moving logic from RLock.acquire to acquire_timed() so that both locks benefit.
Improvement, on a 64 bit windows machine:
Before:
D:\pydev\hg\cpython3\PCbuild\amd64>.\python.exe -m timeit -s "from _thread import allocate_lock" "allocate_lock()"
1000000 loops, best of 3: 0.725 usec per loop
D:\pydev\hg\cpython3\PCbuild\amd64>.\python.exe -m timeit -s "from _thread import allocate_lock; l=allocate_lock()" "l.acquire();l.release()"
1000000 loops, best of 3: 0.315 usec per loop
After:
D:\pydev\hg\cpython3\PCbuild\amd64>.\python.exe -m timeit -s "from _thread import allocate_lock" "allocate_lock()"
1000000 loops, best of 3: 0.691 usec per loop
D:\pydev\hg\cpython3\PCbuild\amd64>.\python.exe -m timeit -s "from _thread import allocate_lock; l=allocate_lock()" "l.acquire();l.release()"
1000000 loops, best of 3: 0.294 usec per loop
This amounts to 5% and 7% improvement, respectively.
----------
files: lock.patch
keywords: patch
messages: 163335
nosy: kristjan.jonsson
priority: normal
severity: normal
status: open
title: _thread.LockType: Optimize lock deletion, acquisition of uncontested lock and release of lock.
Added file: http://bugs.python.org/file26066/lock.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15124>
_______________________________________
More information about the New-bugs-announce
mailing list