caiogondim / fast-memoize.js

:rabbit2: Fastest possible memoization library
https://npm.im/fast-memoize
MIT License
2.58k stars 86 forks source link

Is fast-memoize still the best memoization lib? Is it being maintained? #86

Open theahura opened 1 year ago

theahura commented 1 year ago

Basically the title! Curious if there is some new state-of-the-art for fast memoization, or if this library is still best in class.

ThomasF85 commented 1 year ago

The benchmarking implemented here only tests for the memoized function to be called with one and the same argument (or only a handful of arguments) over and over again. If you test with more different arguments the results for fast-memoize are quite different. Check out our benchmarks here: https://github.com/Animus-Blue/sonic-memoize We implemented benchmarking with a set of 1000 different arguments. So for the first 1000 function calls the memoized function is calling the original expensive function under the hood and all consecutive function calls hit the cache.

bellmatthewf commented 1 year ago

Sonic-memoize does look fast based on those benchmarks. I ended up going with memoizee based on a combination of benchmarks and how much usage it had.

I wanted to just stick to lodash, but the syntax for multi argument memoization is gross.

binary-signal commented 1 year ago

Did few benchmark and fast-memoize was slower than lodash memoize on most of the functions benchmarked on my code base, your use case might be different tho, better to benchmark and then decide. Worth mentioning sonic-memoize was the fastest for my usecase.

func 1 // no cache a: 1.141s // memoizee a: 368.892ms // fast-memoize a: 4.047s // lodash-memoize a: 335.994ms // sonic-memoize: a: 241.388ms

func 2 // no cache a: 1.551s // memoizee a: 1.558s // fast-memoize a: 1.763s // lodash-memoize a: 1.925s //sonic-memoize a: 551.161ms