Repository navigation
Commit 6954733
Release the GIL during DH and DSA parameter generation (#15364)
* Release the GIL during DH and DSA parameter generation
DH parameter generation runs for seconds to minutes at common key sizes
and DSA parameter generation for hundreds of milliseconds, all while
holding the GIL and freezing every other thread in the process. Wrap the
OpenSSL calls in Python::detach; neither closure touches Python objects.
Deliberately NOT detached: EC keygen (~20 us), and DH/DSA
generate_private_key (sub-millisecond to low-millisecond). Re-attaching
after a detach can wait up to sys.getswitchinterval() (5 ms default) when
another thread is CPU-bound, so detaching operations much shorter than
the switch interval makes them dramatically slower under contention
(measured: EC keygen 55 us -> 5.1 ms per op with a busy background
thread). Only operations that run for at least tens of milliseconds are
worth detaching here.
Benchmark (Linux x86-64, CPython 3.11, release build; background Python
thread's progress while the main thread generates):
dsa.generate_parameters(2048): background thread throughput
1.0M iters/s -> 27M iters/s (i.e. other threads now actually run)
ec.generate_private_key / generate_private_key: unchanged
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01C5bsKENedjVD9gcLApf1x4
* Remove comments per review
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01C5bsKENedjVD9gcLApf1x4
---------
Co-authored-by: Claude <[email protected]>1 parent 6893b94 commit 6954733
2 files changed
Lines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | | - | |
| 58 | + | |
| 59 | + | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
| 56 | + | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
0 commit comments