New submission from Kristján Valur Jónsson <krist...@ccpgames.com>:

The attached patch does three things:

"
- Abstract the condition variable used by ceval_gil.h into a separate file,
condvar.h.  It now defines a PyMUTEX_T, PyCOND_T and associated functions.
This file can be used by different parts of the python core.
- Implement locking on windows using custom structures based on condition
variables, rather than using a semaphore kernel object.  This avoids kernel
transitions for uncontensted locks and provides a large speedup for windows.
- Add a condition variable implementation using native primitives for builds
targeted for Vista.  Experimental and disabled by default.
"

Using this locking mechanism on windows results in a 60% speedup of using 
uncontested locks, due to the removal of the necessary kernel transition that 
is required by regular semaphore objects.

Before:
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.731 usec per loop

After:
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.27 usec per loop

----------
components: Interpreter Core, Windows
files: 77369.patch
keywords: patch
messages: 162545
nosy: kristjan.jonsson, loewis, pitrou
priority: normal
severity: normal
status: open
title: Optimize python Locks on Windows
type: enhancement
versions: Python 3.3
Added file: http://bugs.python.org/file25867/77369.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15038>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to