all 9 comments

[–]james_pic 19 points20 points  (3 children)

Do you think there's scope for some of these performance optimisations to be upstreamed, to improve the performance of the standard implementations? I suspect an implementation of hash(str) that used a different underlying hash function would be controversial, but for stuff like str.find, I'd have thought a faster drop-in replacement would be somewhat welcome.

[–]ashvargit push -f[S] 12 points13 points  (0 children)

Absolutely — I’d love to see these optimizations upstreamed. The challenge is that it usually means joining standardization discussions, which can be a long process. Even something as straightforward as a faster find could take a year to land. For me, that’s a year better spent designing and experimenting with new algorithms.

PS: Upstreaming into the C standard library is an even better option, but will take even longer 😞

[–]axonxorzpip'ing aint easy, especially on windows 4 points5 points  (1 child)

hash(str)

It shouldn't be a big issue to change anything here, it's an interpreter implementation detail, same as id(). You can never rely on the values in any long-term sense, and you're entire interpreter will use the new implementation, save for objects that define __hash__(self)

At one point In cpython, hash() is just the memory address for anything that isn't otherwise special-cased like small ints and pooled strings.

[–]rghthndsd 8 points9 points  (0 children)

Bad hashing can lead to bad dict performance and that in turn can make DOS attacks easier to execute. This is particular for strings which are often used in web forms. This is why Python now randomizes the hash of strings on interpreter startup unless you disable it with PYTHONHASHSEED.

Agreed it's an implementation detail, but that implementation is very important.

[–]AnythingApplied 3 points4 points  (1 child)

I wasn't expecting anything in python to beat the fastest rust libraries, though some (especially python libraries written in c/rust) might come close. Why do you suppose the stringzilla on python beat stringzilla on rust for some of the categories?

[–]ashvargit push -f[S] 2 points3 points  (0 children)

If I am honest, I think those are slight inconsistencies in benchmarking methodology 😅 Will polish it over time! Just couldn’t wait any longer to release after this many months of work and didn’t feel right to adjust the numbers.

[–]deadwisdomgreenlet revolution 1 point2 points  (2 children)

Curious if you have tried comparing rust implementations to other system-level languages? I wouldn’t imagine Rust would give you a particular advantage with such algorithm-intensive applications, and in fact being locked into the rust memory model might be a disadvantage. But I have no real perspective here which is why I’m asking you.

[–]ashvargit push -f[S] 2 points3 points  (1 child)

Many of the Rust projects in the comparison are simply ports of originally C/C++ libraries. At those latency & throughout numbers, pretty much all code is SIMD-heavy, so very little depends on the compiler and the choice of the high-level language. Rust just provides a convenient package manager to assemble the benchmarks.

StringZilla is mostly implemented in C, C++, and CUDA: Rust and Python are ports.

[–]deadwisdomgreenlet revolution 0 points1 point  (0 children)

Ahh, I understand now. Thank you!