-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release GIL during cipher update #11900
base: main
Are you sure you want to change the base?
Conversation
Can you share anything about the performance impact of this? I'm modestly nervous about performance overhead for very small chunks, but what can you do 🙃 |
Releasing the GIL should be order of microseconds. I could put together a benchmark for small blocks to see if the overhead is meaningful |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can share some performance numbers, we can get this merged. Thanks!
Ooops, crossed streams :-) Do you have any numbers for the impact of this on your application? |
I can get some for you hopefully tonight, thanks for the quick review! |
Sounds great, thanks for the contribution |
Just a quick ping re: perf numbers 😄 |
I ran some tests on an M1 Max (10 cores, 10 threads) and it appears GIL release is slower than single threading up to ~23kB Some numbers:
These were derived using the following script and varying the size of import time
import concurrent.futures
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms
TOTAL = 1024 * 1024 * 100
DATA = bytes(64)
ITERATIONS = TOTAL // len(DATA)
KEY = bytes(32)
start = time.time()
def encrypt(num):
buf = bytearray(len(DATA))
c = Cipher(algorithms.ChaCha20(KEY, b"0" * 16), None)
encryptor = c.encryptor()
for _ in range(ITERATIONS):
encryptor.update_into(DATA, buf)
print(f"{num} thread complete. {ITERATIONS * len(DATA) / 1024 / 1024} MiB encrypted")
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(encrypt, range(0, 10))
print(time.time() - start) |
Related to discussion in #11585.