PyO3 / rust-numpy

PyO3-based Rust bindings of the NumPy C-API
BSD 2-Clause "Simplified" License
1.11k stars 106 forks source link

Use AHash for borrow checking hash tables. #306

Closed adamreichold closed 2 years ago

adamreichold commented 2 years ago

This does bring a measurable performance improvement for borrow operations

 name                      std ns/iter  ahash ns/iter  diff ns/iter   diff %  speedup 
 additional_shared_borrow  208          140                     -68  -32.69%   x 1.49 
 exclusive_borrow          233          186                     -47  -20.17%   x 1.25 
 initial_shared_borrow     289          211                     -78  -26.99%   x 1.37 

by adding a relatively small dependency on the ahash crate.

adamreichold commented 2 years ago

Sneaky! Should we be considering fxhash also?

I don't think so as we do not control the addresses at which the NumPy arrays are allocated and hence using a non-keyed hash like fxhash would open us up to denial of service attacks.

davidhewitt commented 2 years ago

Makes sense, ahash it is 👍