-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: GH10213 kth_smallest GIL release #10927
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
Changes from all commits
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 |
---|---|---|
|
@@ -69,14 +69,15 @@ Releasing the GIL | |
|
||
We are releasing the global-interpreter-lock (GIL) on some cython operations. | ||
This will allow other threads to run simultaneously during computation, potentially allowing performance improvements | ||
from multi-threading. Notably ``groupby`` and some indexing operations are a benefit from this. (:issue:`8882`) | ||
from multi-threading. Notably ``groupby``, ``nsmallest`` and some indexing operations benefit from this. (:issue:`8882`) | ||
|
||
For example the groupby expression in the following code will have the GIL released during the factorization step, e.g. ``df.groupby('key')`` | ||
as well as the ``.sum()`` operation. | ||
|
||
.. code-block:: python | ||
|
||
N = 1e6 | ||
N = 1000000 | ||
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.
|
||
ngroups = 10 | ||
df = DataFrame({'key' : np.random.randint(0,ngroups,size=N), | ||
'data' : np.random.randn(N) }) | ||
df.groupby('key')['data'].sum() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -740,7 +740,7 @@ ctypedef fused numeric: | |
float64_t | ||
|
||
|
||
cdef inline Py_ssize_t swap(numeric *a, numeric *b) except -1: | ||
cdef inline Py_ssize_t swap(numeric *a, numeric *b) nogil except -1: | ||
cdef numeric t | ||
|
||
# cython doesn't allow pointer dereference so use array syntax | ||
|
@@ -756,27 +756,27 @@ cpdef numeric kth_smallest(numeric[:] a, Py_ssize_t k): | |
cdef: | ||
Py_ssize_t i, j, l, m, n = a.size | ||
numeric x | ||
|
||
l = 0 | ||
m = n - 1 | ||
|
||
while l < m: | ||
x = a[k] | ||
i = l | ||
j = m | ||
|
||
while 1: | ||
while a[i] < x: i += 1 | ||
while x < a[j]: j -= 1 | ||
if i <= j: | ||
swap(&a[i], &a[j]) | ||
i += 1; j -= 1 | ||
|
||
if i > j: break | ||
|
||
if j < k: l = i | ||
if k < i: m = j | ||
return a[k] | ||
with nogil: | ||
l = 0 | ||
m = n - 1 | ||
|
||
while l < m: | ||
x = a[k] | ||
i = l | ||
j = m | ||
|
||
while 1: | ||
while a[i] < x: i += 1 | ||
while x < a[j]: j -= 1 | ||
if i <= j: | ||
swap(&a[i], &a[j]) | ||
i += 1; j -= 1 | ||
|
||
if i > j: break | ||
|
||
if j < k: l = i | ||
if k < i: m = j | ||
return a[k] | ||
|
||
|
||
cdef inline kth_smallest_c(float64_t* a, Py_ssize_t k, Py_ssize_t n): | ||
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 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. this 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. ok, good start on this..... |
||
|
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.
So that the first
test_parallel
call doesn't have to do the initialization.