-
-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
bpo-36051: drop GIL during large b''.join operations #17757
Conversation
Improve multi-threaded performance by dropping the GIL in the fast path of bytes.join. To avoid increasing overhead for small joins, it is only done if the output size exceeds a threshold.
For now I've only made the change for the b''.join fast-path, but if there is agreement I could also add it to the general case (non-empty separator). I think the code is safe against another thread mutating the sequence while the GIL is dropped (because the setup code takes it own refs to all the items), but it would be good if someone could double-check it. |
The existing stress test is increased in size to exceed GIL_THRESHOLD, and a new stress test is added with an empty separator (since that is a separate code path).
The GIL is now also dropped in the code path with non-empty separator, but it is *not* dropped if any of the items is not a `bytes` object (see discussion in bpo-36051 for reasoning).
Benchmarking shows that for smaller thresholds the multi-threading performance tends to be worse, or at least not much better.
@@ -0,0 +1 @@ | |||
Drop the GIL during large ``bytes.join`` operations. |
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.
Add your name in ACKS (see https://devguide.python.org/pullrequest/#crediting),
and add "Patch by ...." here.
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.
I've already added myself to ACKS, but have now added "Patch by ...".
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.
I can not find "Bruce Merry" in ACKS.
https://github.com/python/cpython/blob/master/Misc/ACKS
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.
That's the master version of ACKS. I'm adding myself in this pull request: https://github.com/bmerry/cpython/blob/bpo-36051/Misc/ACKS#L1109
|
Improve multi-threaded performance by dropping the GIL in the fast path of bytes.join. To avoid increasing overhead for small joins, it is only done if the output size exceeds a threshold.
Improve multi-threaded performance by dropping the GIL in the fast path
of bytes.join. To avoid increasing overhead for small joins, it is only
done if the output size exceeds a threshold.
https://bugs.python.org/issue36051