Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

memize

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memize - npm Package Compare versions

Comparing version
2.1.0
to
2.1.1
+81
dist/index.d.cts
export = memize;
/**
* Memize options object.
*
* @typedef MemizeOptions
*
* @property {number} [maxSize] Maximum size of the cache.
*/
/**
* Internal cache entry.
*
* @typedef MemizeCacheNode
*
* @property {?MemizeCacheNode|undefined} [prev] Previous node.
* @property {?MemizeCacheNode|undefined} [next] Next node.
* @property {Array<*>} args Function arguments for cache
* entry.
* @property {*} val Function result.
*/
/**
* Properties of the enhanced function for controlling cache.
*
* @typedef MemizeMemoizedFunction
*
* @property {()=>void} clear Clear the cache.
*/
/**
* Accepts a function to be memoized, and returns a new memoized function, with
* optional options.
*
* @template {(...args: any[]) => any} F
*
* @param {F} fn Function to memoize.
* @param {MemizeOptions} [options] Options object.
*
* @return {((...args: Parameters<F>) => ReturnType<F>) & MemizeMemoizedFunction} Memoized function.
*/
declare function memize<F extends (...args: any[]) => any>(fn: F, options?: MemizeOptions | undefined): ((...args: Parameters<F>) => ReturnType<F>) & MemizeMemoizedFunction;
declare namespace memize {
export { MemizeOptions, MemizeCacheNode, MemizeMemoizedFunction };
}
/**
* Memize options object.
*/
type MemizeOptions = {
/**
* Maximum size of the cache.
*/
maxSize?: number | undefined;
};
/**
* Properties of the enhanced function for controlling cache.
*/
type MemizeMemoizedFunction = {
/**
* Clear the cache.
*/
clear: () => void;
};
/**
* Internal cache entry.
*/
type MemizeCacheNode = {
/**
* Previous node.
*/
prev?: (MemizeCacheNode | undefined) | null;
/**
* Next node.
*/
next?: (MemizeCacheNode | undefined) | null;
/**
* Function arguments for cache
* entry.
*/
args: Array<any>;
/**
* Function result.
*/
val: any;
};
+2
-3
{
"name": "memize",
"version": "2.1.0",
"version": "2.1.1",
"description": "Unabashedly-barebones memoization library with an aim toward speed",

@@ -11,7 +11,6 @@ "type": "module",

},
"types": "dist/index.d.ts",
"scripts": {
"build": "npm run build:bundle && npm run build:types",
"build:bundle": "rollup -c rollup.config.js",
"build:types": "tsc -b tsconfig.decl.json",
"build:types": "tsc -b tsconfig.decl.json && tsc -b tsconfig.decl.cts.json",
"test:unit": "NODE_ENV=test mocha",

@@ -18,0 +17,0 @@ "test:lint": "eslint .",

+9
-45
Memize
======
Memize is a unabashedly-barebones memoization library with an aim toward speed. By all accounts, Memize is __the fastest memoization implementation__ in JavaScript (see [benchmarks](#benchmarks), [how it works](#how-it-works)). It supports multiple arguments, including non-primitive arguments (by reference). All this weighing in at less than 0.3kb minified and gzipped, with no dependencies.
Memize is a unabashedly-barebones memoization library with an aim toward speed.
Why use Memize?
- 🚀 **It's very fast.** Implemented as a least recently used (LRU) cache, it's heavily optimized for scenarios where the function is called repeatedly with the same arguments.
- 🔬 **It's tiny.** It weighs in at less than 0.3kb minified and gzipped, with no dependencies.
- 🔀 **It supports common arguments patterns**, including multiple arguments and non-primitive arguments (by reference).
## Example

@@ -55,48 +61,6 @@

The following benchmarks are performed in Node 10.16.0 on a MacBook Pro (2019), 2.4 GHz 8-Core Intel Core i9, 32 GB 2400 MHz DDR4 RAM.
Implemented as a least recently used (LRU), Memize is heavily optimized for scenarios where the function is called repeatedly with the same arguments. In these scenarios, Memize outperformed most other memoization libraries at the time of initial publication.
__Single argument__
To learn more about these benchmarks, important caveats, and how to run them yourself, refer to [`benchmark/README.md`](./benchmark/README.md).
Name | Ops / sec | Relative margin of error | Sample size
-------------------|-------------|--------------------------|------------
fast-memoize | 360,812,575 | ± 0.55% | 87
memize | 128,909,282 | ± 1.06% | 87
moize | 102,858,648 | ± 0.66% | 88
lru-memoize | 71,589,564 | ± 0.90% | 88
lodash | 49,575,743 | ± 1.00% | 88
underscore | 35,805,268 | ± 0.86% | 88
memoizee | 35,357,004 | ± 0.55% | 87
moize (serialized) | 27,246,184 | ± 0.88% | 87
memoizerific | 8,647,735 | ± 0.91% | 91
ramda | 8,011,334 | ± 0.74% | 90
memoizejs | 2,111,745 | ± 0.52% | 88
_**\* Note**: `fast-memoize` uses [`Function.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length) to optimize for singular argument functions, which [can yield unexpected behavior](https://github.com/caiogondim/fast-memoize.js#rest--default-parameters) if not account for._
__Multiple arguments (primitive)__
Name | Ops / sec | Relative margin of error | Sample size
-------------------|------------|--------------------------|------------
memize | 81,460,517 | ± 0.61% | 88
moize | 66,896,395 | ± 0.90% | 83
lru-memoize | 26,315,198 | ± 1.26% | 85
memoizee | 18,237,056 | ± 0.60% | 90
moize (serialized) | 15,207,105 | ± 0.78% | 84
memoizerific | 6,363,555 | ± 0.63% | 88
memoizejs | 1,764,673 | ± 0.57% | 90
fast-memoize | 1,560,421 | ± 0.72% | 87
__Multiple arguments (non-primitive)__
Name | Ops / sec | Relative margin of error | Sample size
-------------------|------------|--------------------------|------------
memize | 79,105,918 | ± 0.81% | 86
moize | 62,374,610 | ± 0.55% | 87
lru-memoize | 24,814,747 | ± 0.54% | 89
memoizee | 12,119,005 | ± 0.47% | 89
memoizerific | 6,748,675 | ± 0.66% | 88
moize (serialized) | 2,027,250 | ± 1.07% | 87
fast-memoize | 1,263,457 | ± 1.00% | 89
memoizejs | 1,075,690 | ± 0.61% | 87
## How it works

@@ -103,0 +67,0 @@