有许多JavaScript库可以用来记忆函数。
对于各种使用情况,有哪些最好的(高质量,灵活,快速等)?
有许多JavaScript库可以用来记忆函数。
对于各种使用情况,有哪些最好的(高质量,灵活,快速等)?
我发现有很多不同的JavaScript记忆库,它们都以稍微不同的方式运作。
我将尝试在这里列出和比较“最佳”的库。(按照我估计它们的效果/通用性的顺序排列;或者说,那是计划,一旦我有时间进一步了解它们!)
核心特性:(标记为 ✔️ 是、❌ 否、⚙️ 部分、❔ 未知)
核心功能) npm: ✔️,m-arg: ✔️,o-arg: ✔️,o-hash: ❌,m-slot: ✔️,auto: ✔️
受欢迎程度) GitHub 星数:~550;NPM 每周下载量:~76k(截至2020年4月24日)
核心功能) npm: ✔️,m-arg: ✔️,o-arg: ✔️,o-hash: ⚙️,m-slot: ✔️,auto: ✔️
受欢迎程度) GitHub 星数:~1.1k;NPM 每周下载量:~1.9m(截至2020年4月24日)
核心功能) npm: ✔️,m-arg: ✔️,o-arg: ✔️,o-hash: ✔️,m-slot: ✔️,auto: ✔️
受欢迎程度) GitHub 星数:~850;NPM 每周下载量:~60k(截至2020年4月24日)
核心功能) npm: ✔️,m-arg: ✔️,o-arg: ✔️,o-hash: ❌,m-slot: ✔️,auto: ✔️
受欢迎程度) GitHub 星数:~2.2k;NPM 每周下载量:~381k(截至2020年4月24日)
核心特性) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️
lodash.memoize (代码)
核心特性) npm: ✔️, m-arg: ❌, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️
memoize-weak
核心特性) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️
memoize-immutable
核心特性) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ✔️, m-slot: ✔️, auto: ✔️
underscore.memoize (代码)
核心特性) npm: ✔️, m-arg: ❌, o-arg: ✔️, o-hash: ❌, m-slot: ✔️, auto: ✔️
memoize-state
核心特性) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
kashe
nano-memoize
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
memoizerific
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
memoize-fn
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
memoize-cache
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
memoize-one
核心功能) npm: ✔️, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❌, auto: ❔
use-memo-one
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❌, auto: ❔
@emotion/weak-memoize
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
lru-memoizer
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
mem
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
memoizejs
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
memize
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
reselect
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❌
rememo
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❌
memoize-bind
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
memoizesync
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
@thi.ng/memoize
核心功能) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
trie-memoize
核心特点) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
memobind
核心特点) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
memoize-id
核心特点) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
@bigcommerce/memoize
核心特点) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
针对异步函数
mobx-utils:computedFn
[请参考上面同步类别中的条目]
p-memoize
核心特点) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
node-memoizeasync
核心特点) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
promise-memoize
核心特点) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
use-async-memo
async-memo-ize
核心特点) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
memoize-async
核心特点) npm: ❔, m-arg: ❔, o-arg: ❔, o-hash: ❔, m-slot: ❔, auto: ❔
讨论
实际上,JS记忆化库比这还多(我知道...),但我已经排除了以下情况的库:
- 无法在内存中记忆化。 (例如仅基于文件的缓存)
- 无法记忆化独立的函数。 (例如仅限类方法)
- 不是开源的,或托管在一些疯狂的地方 像这样 太诡异了。
- 超出了前几页的搜索结果。(一个人只能花这么多时间...)