There are many Javascript libraries out there for memoizing functions.
What are some of the best ones (high quality, flexible, fast, etc.), for the various use-cases?
There are many Javascript libraries out there for memoizing functions.
What are some of the best ones (high quality, flexible, fast, etc.), for the various use-cases?
I've found that there are tons of different JavaScript memoization libraries out there, and they all operate in slightly different ways.
I'll attempt to list and compare the "best" ones here. (ordered roughly by how effective/general-purpose I estimate them to be; or rather, that's the plan once I have time to look them over further!)
Core features: (marked with ✔️yes, ❌no, ⚙️partial, ❔unknown)
npm) Install from NPM: The package is available on npm. (for easy integration/updating)
m-arg) Multiple arguments: Can memoize functions that are passed multiple arguments.
o-arg) Object arguments: Can memoize functions that are passed object arguments.
o-hash) Object hashing: Can memoize using the internal JS hashing forobject
arguments, through use ofMap
/WeakMap
. (better perf than serialization or cache-entry iteration)
m-slot) Multiple slots: Can store cached results for more than just the last set of arguments. (without requiring manual creation of new "cache slots" / "instantiations")
auto) Auto-memoize: Can memoize based on the regular passed arguments; does not require function-specific setup/wrapping for basic memoization. (may still require a generic wrapping)
Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ❌, m-slot: ✔️, auto: ✔️
Popularity) GitHub stars: ~550; NPM weekly downloads: ~76k (2020-04-24)
Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ⚙️, m-slot: ✔️, auto: ✔️
Popularity) GitHub stars: ~1.1k; NPM weekly downloads: ~1.9m (2020-04-24)
Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️
Popularity) GitHub stars: ~850; NPM weekly downloads: ~60k (2020-04-24)
Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ❌, m-slot: ✔️, auto: ✔️
Popularity) GitHub stars: ~2.2k; NPM weekly downloads: ~381k (2020-04-24)
Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️
Core features) npm: ✔️, m-arg: ❌, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️
Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️
Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️
Core features) npm: ✔️, m-arg: ❌, o-arg: ✔️, o-hash: ❌, m-slot: ✔️, auto: ✔️
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ✔️, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❌, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❌, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❌
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❌
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
[see entry above in synchronous category]
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
There are actually many more JS memoization libraries than this (I know...), but I've left out ones where the library: