哪些备忘录库可用于Javascript? [英] What memoization libraries are available for Javascript?

查看:91
本文介绍了哪些备忘录库可用于Javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有许多用于记忆功能的Javascript库.

针对各种用例,最好的是哪些(高质量,灵活,快速等)?

解决方案

我发现这里有个不同的JavaScript备注库,它们的运行方式略有不同. /p>

我将在此处尝试列出和比较最佳"产品. (大致取决于我估计它们的有效性/通用性;或更确切地说,一旦我有时间进一步研究它们,那就是该计划!)

核心功能 :(标有✔️yes,❌no,⚙️partial,❔未知)

npm)从NPM安装:该软件包可在npm上使用. (以便于集成/更新)
m-arg)多个参数:可以记住传递多个参数的函数.
o-arg)对象参数:可以记住传递给对象参数的函数.
o-hash)对象哈希:可以通过使用Map/WeakMap来对object参数使用内部JS哈希进行存储. (比序列化或缓存项迭代更好的性能)
m插槽)多个插槽:可以存储缓存的结果,而不仅仅是最后一组参数. (无需手动创建新的缓存插槽"/实例")
自动)自动存储:可以基于常规传递的参数进行存储;不需要功能特定的设置/包装即可进行基本备注. (可能仍需要通用包装)

用于同步功能

moize (基于微记忆)

核心功能) npm :✔️,m-arg:✔️,o-arg: ✔️,o-hash:❌,m-slot:✔️,auto:✔️
人气)GitHub星星:〜550; NPM每周下载:〜76k

memoizee

核心功能) npm :✔️,m-arg:✔️,o-arg: ✔️,o-hash:⚙️,m-slot:✔️,auto:✔️
人气)GitHub星星:〜1.1k; NPM每周下载:〜190万

mobx-utils:computedFn

核心功能) npm :✔️,m-arg:✔️,o- arg:✔️,o-hash:✔️,m-slot:✔️,auto:✔️
人气)GitHub星星:〜850; NPM每周下载:〜60k

快速记忆

核心功能) npm :✔️,m-arg:✔️,o- arg:✔️,o-hash:❌,m-slot:✔️,auto:✔️
人气)GitHub星星:〜2.2k; NPM每周下载:〜381k

地图备忘录

核心功能) npm :✔️,m-arg:✔️ ,o-arg:✔️,o-hash:✔️,m-slot:✔️,auto:✔️

lodash.memoize ( npm :✔️,m-arg:❌,o- arg:✔️,o-hash:✔️,m-slot:✔️,auto:✔️

记忆减弱

核心功能) npm :✔️,m-arg:✔️,o- arg:✔️,o-hash:✔️,m-slot:✔️,auto:✔️

存储不变的

核心功能) npm :✔️,m-arg:✔️,o- arg:✔️,o-hash:✔️,m-slot:✔️,auto:✔️

underscore.memoize ( npm :✔️,m-arg:❌,o-arg: ✔️,o-hash:❌,m-slot:✔️,auto:✔️

记忆状态

核心功能)npm:❔,m-arg:o,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

kashe

核心功能)npm:❔,m-arg:o,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

nano-memoize

核心功能)npm:❔,m-arg:o,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

记忆化

核心功能)npm:❔,m-arg:o,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

memoize-fn

核心功能)npm:❔,m-arg:o,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

memoize-cache

核心功能)npm:❔,m-arg:❔,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

记住一个

核心功能) npm :✔️,m-arg:❔,o- arg:❔,o-hash:-,m-slot:❌,auto:❔

use-memo-one

核心功能)npm:❔,m-arg:o,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,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

内存

核心功能)npm:❔,m-arg:o,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

memoizejs

核心功能)npm:❔,m-arg:❔,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

记忆化

核心功能)npm:❔,m-arg:❔,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

重新选择

核心功能)npm:❔,m-arg:❔,o-arg:-,o-hash:❔,m-slot:❔,auto:❌

纪念品

核心功能)npm:❔,m-arg:❔,o-arg:-,o-hash:❔,m-slot:❔,auto:❌

memoize-bind

核心功能)npm:❔,m-arg:o,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

memoizesync

核心功能)npm:❔,m-arg:o,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,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

memobind

核心功能)npm:❔,m-arg:❔,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

memoize-id

核心功能)npm:❔,m-arg:o,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

@ bigcommerce/memoize

核心功能)npm:❔,m-arg:o,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

用于异步功能

mobx-utils:computedFn

[请参见上面同步类别中的条目]

p-memoize

核心功能)npm:❔,m-arg:o,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

node-memoizeasync

核心功能)npm:❔,m-arg:❔,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

承诺存储

核心功能)npm:❔,m-arg:o,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

use-async-me

核心功能)npm:❔,m-arg:❔,o-arg:-,o-hash:❔,m-slot:❔,auto:❔

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记忆库比这个要多(我知道...),但是我省略了其中的库:

  • 无法记住内存. (例如,仅基于文件的缓存)
  • 无法记住独立功能. (例如,仅适用于类方法)
  • 不是开源的,也不是在某个疯狂的地方托管 解决方案

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

memoizee

Core features) npm: ✔️, m-arg: ✔️, o-arg: ✔️, o-hash: ⚙️, m-slot: ✔️, auto: ✔️
Popularity) GitHub stars: ~1.1k; NPM weekly downloads: ~1.9m

mobx-utils:computedFn

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

fast-memoize

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

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...)

这篇关于哪些备忘录库可用于Javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆