Giter Club home page Giter Club logo

fast-memoize.js's Introduction

fast-memoize

Travis CI David DM js-standard-style

In computing, memoization is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again. โ€” Wikipedia

This library is an attempt to make the fastest possible memoization library in JavaScript that supports N arguments.

There are already very popular solutions for this problem, but they are not fast enough or accept only one argument.

Installation

To use the library, install it through npm

npm install fast-memoize

To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack

Usage

const memoize = require('fast-memoize')

const fn = function (one, two, three) { /* ... */ }

const memoized = memoize(fn)

memoized('foo', 3, 'bar')
memoized('foo', 3, 'bar') // Cache hit

Benchmark

There is already plenty of libraries that does memoization on JS world. underscore and lodash provides it, but they don't accept more than one argument. memoizee is a very well written library that supports N arguments, but is not even close on performance to lodash.

Below you can see a performance benchmark between some of the most popular libraries for memoization.

fast-memoize is faster than any other library but lodash. The reason why is that lodash does not support N arguments and is very optimized to that unique use case. But even though, fast-memoize is the library that supports N that comes closer to it.

To run the benchmark, clone the repo, install the dependencies and run npm run benchmark.

git clone [email protected]:caiogondim/fast-memoize.git
cd fast-memoize
npm install
npm run benchmark

Support

Desktop browsers

Chrome IE Firefox Safari Opera Edge Brave
Latest 8+ Latest Latest Latest Latest Latest

Mobile browsers

| Chrome | Safari | Android Browser | IE | Firefox | Opera | UC | | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Latest | 6+ | 4.0+ | 8+ | Latest | Latest | Latest |

Server

0.10+ โœ”

Reference

Credits

fast-memoize.js's People

Contributors

caiogondim avatar leobalter avatar elliotthill avatar

Watchers

Tom Leo avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.