Skip to content Skip to sidebar Skip to footer

What Memoization Libraries Are Available For Javascript?

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?

Solution 1:

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 for object arguments, through use of Map/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)

For synchronous functions

moize (based on micro-memoize)

Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ❌, m-slot: ✔️, auto: ✔️ Popularity) GitHub stars: ~550; NPM weekly downloads: ~76k (2020-04-24)

memoizee

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)

mobx-utils:computedFn

Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️ Popularity) GitHub stars: ~850; NPM weekly downloads: ~60k (2020-04-24)

fast-memoize

Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ❌, m-slot: ✔️, auto: ✔️ Popularity) GitHub stars: ~2.2k; NPM weekly downloads: ~381k (2020-04-24)

map-memo

Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️

lodash.memoize (code)

Core features) npm: ✔️, m-arg: ❌, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️

memoize-weak

Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️

memoize-immutable

Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️

underscore.memoize (code)

Core features) npm: ✔️, m-arg: ❌, o-arg: ✔️, o-hash: ❌, m-slot: ✔️, auto: ✔️

memoize-state

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

kashe

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

nano-memoize

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

memoizerific

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

memoize-fn

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

memoize-cache

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

memoize-one

Core features) npm: ✔️, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❌, auto: ❔

use-memo-one

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❌, auto: ❔

@emotion/weak-memoize

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

lru-memoizer

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

mem

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

memoizejs

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

memize

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

reselect

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❌

rememo

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❌

memoize-bind

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

memoizesync

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

@thi.ng/memoize

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

trie-memoize

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

memobind

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

memoize-id

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

@bigcommerce/memoize

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

For asynchronous functions

mobx-utils:computedFn

[see entry above in synchronous category]

p-memoize

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

node-memoizeasync

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

promise-memoize

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

use-async-memo

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

async-memo-ize

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

memoize-async

Core features) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔

Discussion

There are actually many more JS memoization libraries than this (I know...), but I've left out ones where the library:

  • Cannot memoize in-memory. (eg. file-based cache only)
  • Cannot memoize standalone functions. (eg. class methods only)
  • Is not open-source, or hosted at some crazy place like this XD.
  • Was beyond the first few pages of results. (one can only invest so much time into this...)

Post a Comment for "What Memoization Libraries Are Available For Javascript?"