Skip to content

Release the GIL during core EC and RSA cryptographic operations - #14370

Merged
reaperhulk merged 3 commits into
mainfrom
claude/release-gil-crypto-CJmDa
Feb 24, 2026
Merged

reaperhulk merged 3 commits into
mainfrom
claude/release-gil-crypto-CJmDa

Conversation

@alex

@alex alex commented Feb 24, 2026

Copy link
Copy Markdown
Member

Wrap CPU-intensive OpenSSL calls in py.detach() to release the GIL, allowing other Python threads to run during cryptographic operations.

Operations covered:

  • EC key generation, ECDH key exchange, ECDSA sign/verify
  • RSA key generation, sign/verify, encrypt/decrypt

https://claude.ai/code/session_01TbN4mmRwmt1boDWU8Gwb5E

Wrap CPU-intensive OpenSSL calls in py.detach() to release the GIL,
allowing other Python threads to run during cryptographic operations.

Operations covered:
- EC key generation, ECDH key exchange, ECDSA sign/verify
- RSA key generation, sign/verify, encrypt/decrypt

https://claude.ai/code/session_01TbN4mmRwmt1boDWU8Gwb5E
@alex alex linked an issue Feb 24, 2026 that may be closed by this pull request

@reaperhulk reaperhulk left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(oops didn't mean to write anything here)

Comment thread src/rust/src/backend/ec.rs Outdated
let ossl_curve = curve_from_py_curve(py, curve)?;
let key = openssl::ec::EcKey::generate(&ossl_curve)?;
let pkey = py.detach(|| {
let key = openssl::ec::EcKey::generate(&ossl_curve)?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this isn't worth doing, EC key generation is fast

EC key generation is fast enough that releasing the GIL adds
unnecessary overhead.

https://claude.ai/code/session_01TbN4mmRwmt1boDWU8Gwb5E
@reaperhulk
reaperhulk enabled auto-merge (squash) February 24, 2026 14:13
@reaperhulk
reaperhulk merged commit f22c181 into main Feb 24, 2026
67 checks passed
@reaperhulk
reaperhulk deleted the claude/release-gil-crypto-CJmDa branch February 24, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

GIL is blocked even when library is called from thread

3 participants