-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-148323: release the GIL in bytes.join when operands are immutable
#148456
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Improve performance of :meth:`bytes.join` when the operands are known to be | ||
| buffer views on :class:`bytes` objects (but not subclasses thereof) by | ||
| releasing the GIL during the concatenation. Patch by Bénédikt Tran. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,7 +18,7 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable) | |||||||||||||||||||||
| Py_buffer *buffers = NULL; | ||||||||||||||||||||||
| #define NB_STATIC_BUFFERS 10 | ||||||||||||||||||||||
| Py_buffer static_buffers[NB_STATIC_BUFFERS]; | ||||||||||||||||||||||
| #define GIL_THRESHOLD 1048576 | ||||||||||||||||||||||
| #define GIL_THRESHOLD 1048576 // 0x100000 | ||||||||||||||||||||||
| int drop_gil = 1; | ||||||||||||||||||||||
| PyThreadState *save = NULL; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -81,7 +81,9 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable) | |||||||||||||||||||||
| * races anyway, but this is a conservative approach that avoids | ||||||||||||||||||||||
| * changing the behaviour of that data race. | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| drop_gil = 0; | ||||||||||||||||||||||
| if (!PyBytes_CheckExact(buffers[i].obj)) { | ||||||||||||||||||||||
|
picnixz marked this conversation as resolved.
Outdated
picnixz marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| drop_gil = 0; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+84
to
+87
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor speedup
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it'll matter much honestly. I'll wait for benchmarks in this case. Most of the time will be spent in memcpy() and the rest. |
||||||||||||||||||||||
| } | ||||||||||||||||||||||
| nbufs = i + 1; /* for error cleanup */ | ||||||||||||||||||||||
| itemlen = buffers[i].len; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.