Live data from Hacker News

SeaHash: A fast, portable hash function in Rust

docs.rs

11–20 of 116 posts

Re: SeaHash: A fast, portable hash function in Rust

#11

Great to see another piece of code written in Rust. That said, how do you make claims of something being blazingly fast without any comparisons to implementations in other languages such as C or C++?

Because it's benchmarking a hash function, not a language?

Re: SeaHash: A fast, portable hash function in Rust

#12
This is is not a knock against SeaHash, but I was looking at buffer.rs [0] and noticed pretty much all the code is wrapped in unsafe {} blocks. How much advantage is there to rust implementation vs c++ if unsafe is used so liberally? I ask this in ernest.

[0] https://docs.rs/crate/seahash/2.0.0/source/src/buffer.rs

Re: SeaHash: A fast, portable hash function in Rust

#13
post #12

This is is not a knock against SeaHash, but I was looking at buffer.rs [0] and noticed pretty much all the code is wrapped in unsafe {} blocks. How much advantage is there to rust implementation vs c++ if unsafe is used so liberally? I ask this in ernest. [0] https://docs.rs/crate/seahash/2.0.0/source/src/buffer.rs

None. But once you're out of the buffer code, it's safe.

Re: SeaHash: A fast, portable hash function in Rust

#14
post #12

This is is not a knock against SeaHash, but I was looking at buffer.rs [0] and noticed pretty much all the code is wrapped in unsafe {} blocks. How much advantage is there to rust implementation vs c++ if unsafe is used so liberally? I ask this in ernest. [0] https://docs.rs/crate/seahash/2.0.0/source/src/buffer.rs

It seems like a small kernel of unsafe code, while the rest of the library is likely written safe. Perhaps more of this could be written safe?

Re: SeaHash: A fast, portable hash function in Rust

#15
post #7

Great to see another piece of code written in Rust. That said, how do you make claims of something being blazingly fast without any comparisons to implementations in other languages such as C or C++?

The claim is that it is a blazingly fast hash function compared with other hash functions , and it is also written in Rust. Rust is an enabling technology, but not able to be dramatically faster than a comparable C/C++ implementation, as a general rule.

The title is confusing. If it tries to compete with other hash functions, why does the title have to bear "in Rust"?

Re: SeaHash: A fast, portable hash function in Rust

#16
post #12

This is is not a knock against SeaHash, but I was looking at buffer.rs [0] and noticed pretty much all the code is wrapped in unsafe {} blocks. How much advantage is there to rust implementation vs c++ if unsafe is used so liberally? I ask this in ernest. [0] https://docs.rs/crate/seahash/2.0.0/source/src/buffer.rs

Better integration within the Rust library ecosystem. Instead of having to install a C/C++ library through my package manager, I can just add the seahash dependency to my Cargo.toml file and cargo will handle the rest.

Re: SeaHash: A fast, portable hash function in Rust

#17
post #12

This is is not a knock against SeaHash, but I was looking at buffer.rs [0] and noticed pretty much all the code is wrapped in unsafe {} blocks. How much advantage is there to rust implementation vs c++ if unsafe is used so liberally? I ask this in ernest. [0] https://docs.rs/crate/seahash/2.0.0/source/src/buffer.rs

Because the unsafe code is isolated into an easily-auditable portion that basically just exists to perform word-aligned reads of a byte buffer.

It might be nice to factor this out into a separate library, but it's fairly harmless.

Re: SeaHash: A fast, portable hash function in Rust

#18
post #7

Earlier quoted context omitted.

The claim is that it is a blazingly fast hash function compared with other hash functions , and it is also written in Rust. Rust is an enabling technology, but not able to be dramatically faster than a comparable C/C++ implementation, as a general rule.

The title is confusing. If it tries to compete with other hash functions, why does the title have to bear "in Rust"?

Because it's probably the most notable/unusual part of this hash function. Virtually all other hash functions for at least a decade have had their reference implementations written in C or C++.

Re: SeaHash: A fast, portable hash function in Rust

#19
post #12

This is is not a knock against SeaHash, but I was looking at buffer.rs [0] and noticed pretty much all the code is wrapped in unsafe {} blocks. How much advantage is there to rust implementation vs c++ if unsafe is used so liberally? I ask this in ernest. [0] https://docs.rs/crate/seahash/2.0.0/source/src/buffer.rs

As others have mentioned, Rust allows you to write a safe wrapper around unsafe code. In this case, all of the functions implemented in buffer.rs are safe, even if their contents are not, so they can be used without having to worry about unsafety.

Another advantage over C++ is that it's much more clear what code is safe and what isn't, as unsafe code is wrapped in `unsafe` blocks, as you mentioned.

Re: SeaHash: A fast, portable hash function in Rust

#20
post #12

This is is not a knock against SeaHash, but I was looking at buffer.rs [0] and noticed pretty much all the code is wrapped in unsafe {} blocks. How much advantage is there to rust implementation vs c++ if unsafe is used so liberally? I ask this in ernest. [0] https://docs.rs/crate/seahash/2.0.0/source/src/buffer.rs

> How much advantage is there to rust implementation vs c++ if unsafe is used so liberally?

I'm no expert on the topic. IIRC, Rust does not have the same kind/amount of unspecified behavior as C/C++ do.

FYI: This is a "highly optimized version of SeaHash" (see comment in first line) with "optimized" meaning fiddling with raw pointers. You can find a version without any unsafe code is in `reference.rs`. I have no idea how fast the reference implementation is.

Post reply on HN