nano-memoize | micro ... a nano speed | Runtime Evironment library
kandi X-RAY | nano-memoize Summary
kandi X-RAY | nano-memoize Summary
The devs caiogondim and planttheidea have produced great memoizers. We analyzed their code to see if we could build something faster than fast-memoize and smaller than micro-memoize while adding back some of the functionality of moize removed in micro-memoize. We think we have done it ... but credit to them ... we just merged the best ideas in both and eliminated excess code. During development we also discovered that despite its popularity and goal to be the fastest possible memoizer, fast-memoize is actually one of the slowest out-of-the-box when it comes to multiple argument functions because it uses JSON.stringify to generate a single key generator for all arguments. It also only memoizes out to 3 arguments, which may cause issues. This is not to say it should not be used, it also seems to have the cleanest software architecture and it may be theoretically possible to write a high-speed multi-argument plugin. And, MANY people are very happy with it. Special appreciation to @titoBouzout and @popbee who spent a good bit of time reviewing code for optimization and making recommendations. See Issue 4 for the conversation. The minified/brotli size is 789 bytes for nano-memoize v1.2.0 vs 1,356 bytes for micro-memoize v4.08. And, nano-memoize has slightly more functionality. The speed tests are below. At the time of testing the most recent version of fast-memoize 2.5.1 was a year old. The most recent version of micro-memoize 4.0.8 was 3 months old. We have found that benchmarks can vary dramatically from O/S to O/S or Node version to Node version. These tests were run on a Windows 10 Pro 64bit 1.8ghz i7 machine with 16GB RAM and Node v12.7.0. Also, even with multiple samplings, garbage collection can have a substative impact and multiple runs in different orders are really required for apples-to-apples comparisons. Functions with a single primitive parameter... Functions with a single object parameter... Functions with multiple parameters that contain only primitives... Functions with multiple parameters that contain objects...
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Serialize a function .
- Check if the argument is v .
- generate index function
- Get custom options for custom options
- Returns true if any objects are the same
- Merge additional options with additional options .
- Order in the given cache .
- Create an update cache for the given options .
- Create a memoized function .
- Memoize function .
nano-memoize Key Features
nano-memoize Examples and Code Snippets
Community Discussions
Trending Discussions on nano-memoize
QUESTION
I am trying to use Nano-memoize in my React based web application which also uses Typescript and Webpack.
I have followed the following steps:
npm install nano-memoize
- added
import * as nanomemoize from 'nano-memoize'
to my source file. - memoized a function like
const memoizedFunc = nanomemoize(myFunc)
myFunc
takes two arguments - a string and an string[].
However, I don't see the memoization happening because the debug statements in myFunc
are getting printed for same arguments.
How should this be done the right way?
ANSWER
Answered 2019-Sep-03 at 07:37Nano-memoize doesn't do deep equals comparison of arguments. The string[] arguments passed in to myFunct
is different object each time and consequently memoization doesn't work.
To fix this I am forced to use lodast.isquals as an option in nano-memoize
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install nano-memoize
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page