jaemk / cached

Rust cache structures and easy function memoization
MIT License
1.57k stars 95 forks source link

Allow the use of ahash as the default hasher for more then redis. #171

Closed FilipAndersson245 closed 1 year ago

FilipAndersson245 commented 1 year ago

This PR adds a new feature ahash that changes primarily what hashing algorithm is used to hash data, instead opting for the faster ahash algorithm. It also changes the hashtable implementation instead to be directly depending on hashbrown for sized we already depended directly on hashbrown so there the only change is the ahash hashing compared to the default. The default in hashbrown is to use ahash so for the other ones I opted just to use hashbrown directly. Maybe this could even be simplified as we could use hashbrown everywhere.

✅cargo fmt ✅update changelog

FilipAndersson245 commented 1 year ago

I did a very basic performance comparason using the fib example, using hyperfine

❯ hyperfine --warmup 50 --runs 1000 --shell none './fib' './fib-ahash'
Benchmark 1: ./fib
  Time (mean ± σ):       5.6 ms ±   1.1 ms    [User: 4.5 ms, System: 1.1 ms]
  Range (min … max):     4.5 ms …  13.1 ms    1000 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Benchmark 2: ./fib-ahash
  Time (mean ± σ):       5.2 ms ±   1.2 ms    [User: 4.0 ms, System: 1.2 ms]
  Range (min … max):     3.8 ms …   9.3 ms    1000 runs

Summary
  ./fib-ahash ran
    1.08 ± 0.33 times faster than ./fib
FilipAndersson245 commented 1 year ago

@jaemk anything else that has to be done to merge this PR?

jaemk commented 1 year ago

@FilipAndersson245 sorry for the delay, thank you for adding this! I'll merge and release later today

FilipAndersson245 commented 1 year ago

@FilipAndersson245 sorry for the delay, thank you for adding this! I'll merge and release later today

no problem 😄 What would be your thoughts on making this part of the default? it would not increase compile time as its part of hashbrowns already and has some neat perf improvement.

jaemk commented 1 year ago

I'm on board with making it the default hash algo. Can you also update the crate-level docs explaining that it's the default

FilipAndersson245 commented 1 year ago

I'm on board with making it the default hash algo. Can you also update the crate-level docs explaining that it's the default

done

jaemk commented 1 year ago

@FilipAndersson245 would you mind running make docs and pulling in changes from master

FilipAndersson245 commented 1 year ago

Hello had to do some rebasing of the commits everything should be fine now I believe.