New submission from Kristján Valur Jónsson <krist...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue15124>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to