-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: np.unique and sorting is slow for StringDType #26510
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
Comments
I looked at this again. One thing that immediately helps is switching to a more performant mutex implementation, and indeed running on Python 3.13rc1 that uses PyMutex I found that the stringdtype version beats object array, but unicode is still substantially faster:
So I think it's probably still worth it to special-case the sorting. Or at least do something so the lock only needs to be acquired once. Looking at actually adding special sorting routines would mean re-implementing the algorithms in quicksort.cpp, timsort.cpp, etc etc which seems not worth doing. Maybe better to simply special-case stringdtype sorting in |
Ah, I see why unicode sorting is fast, there's a special case for string sorting in |
How does argsorting compare? Do you actually move strings around, or just change the offsets? |
I also did some basic performance tests in
v2.0.0rc2
for the experimentalStringDType
but it seems to be much slower than"O"
or"U"
dtypes in certain cases, are you aware of these issues:Profiling (will include in a separate comment below) indicates that the overhead is from acquiring and releasing the allocator lock (it does it for every entry in the array because sorting is implemented using getitem).
We could improve performance for sorting specifically by adding a fast getitem path that assumes the allocator lock is already acquired and using it in the sorting implementation after acquiring the lock once.
Optimizing getitem and setitem would also help (maybe by adding a stringdtype scalar that interns the packed string).
Originally posted by @MarkusSintonen in #25693 (comment)
The text was updated successfully, but these errors were encountered: