This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lunixbochs2
Recipients Dennis Sweeney, SD, eryksun, lunixbochs2, ned.deily, paul.moore, pitrou, steve.dower, tim.golden, zach.ware
Date 2021-06-06.21:47:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1623016035.24.0.762503322255.issue41299@roundup.psfhosted.org>
In-reply-to
Content
I just ran into this. GetTickCount64() is a bad choice even without improving the Windows timer resolution, as every mutex wait will have 16ms of jitter. Here are some lock.acquire(timeout=0.001) times measured with time.perf_counter():

elapsed=21.215ms
elapsed=30.960ms
elapsed=21.686ms
elapsed=30.998ms
elapsed=30.794ms

Here's the same lock.acquire(timeout=0.001) with CPython patched to use QueryPerformanceCounter() instead of GetTickCount64(). Notice this is less overhead than even the original post's Python 2.x times.

elapsed=9.554ms
elapsed=14.516ms
elapsed=13.985ms
elapsed=13.434ms
elapsed=13.724ms

Here's the QueryPerformanceCounter() test in a timeBeginPeriod(1) block:

elapsed=1.135ms
elapsed=1.204ms
elapsed=1.189ms
elapsed=1.052ms
elapsed=1.052ms

I'd like to submit a PR to fix the underlying issue by switching to QueryPerformanceCounter() in EnterNonRecursiveMutex().

QueryInterruptTime() is a bad candidate because it's only supported on Windows 10, and CPython still supports Windows 8. Improvements based on QueryPerformanceCounter() can be backported to at least 3.8 (3.8 dropped Windows XP support, which was the last Windows version where QueryPerformanceCounter() could fail).

I checked and the only other use of GetTickCount64() seems to be in time.monotonic(). Honestly I would vote to change time.monotonic() to QueryPerformanceCounter() as well, as QueryPerformanceCounter() can no longer fail on any Windows newer than XP (which is no longer supported by Python), but that's probably a topic for a new BPO.
History
Date User Action Args
2021-06-06 21:47:15lunixbochs2setrecipients: + lunixbochs2, paul.moore, pitrou, tim.golden, ned.deily, zach.ware, eryksun, steve.dower, Dennis Sweeney, SD
2021-06-06 21:47:15lunixbochs2setmessageid: <1623016035.24.0.762503322255.issue41299@roundup.psfhosted.org>
2021-06-06 21:47:15lunixbochs2linkissue41299 messages
2021-06-06 21:47:15lunixbochs2create