memoize-two-args
v1.0.7memoize-two-args
yarn add memoize-two-args
or
npm i memoize-two-args
Aims to solve a common problem which is typically slow or memory-inefficient: memoizing exactly two arguments which are both objects. Typically this is done using an LRU implementation backed by an array structure with O(n)
lookups. This function, however, uses WeakMap
(or Map
if you need to be able to memoize strings, undefined, etc) giving it O(1 * 2)
lookup efficiency.
Usage
memoize(fn, [Map|WeakMap(default)])
import memoize from 'memoize-two-args'
const memoizedFn = memoize(
function (arg1, arg2) {
// do work
}
)
const objA = {...}
const objB = {...}
return memoizedFn(objA, objB)
with Map
...
const memoizedFn = memoize(someFunc, Map)
...
npm i memoize-two-args
Source Code
github.com/jaredlunde/memoiz...Metadata
- MIT
- Whatever
- Jared Lunde
- released 8/18/2018