Hamsters.js
  • Home
  • About
  • Services
  • Examples
    • Atomic Operations
    • Collatz Conjecture
    • Fibonacci Sequence
    • Mandelbrot Set
    • Square Root
  • Wiki
  • Donate
  • Contact
Login
Register

Hamsters.js Wiki

  • Installing Hamsters

    • HTML
    • React Native
    • Node.js
  • Using Hamsters

    • Initializing
    • The Basics
    • Restructuring Standard Functions
    • Promises
    • Sorting
    • Persistence
    • Transferable Objects
    • Atomic Operations
    • Memoization
    • Debugging
    • Limitations

Memoization

Re-introduced in version 5.5.5 of Hamsters.js, Memoize is an optional parameter which enabled the caching of your Hamsters.js function calls, meaning on initial runs of your function Hamsters.js will make use of multiple web workers for parallel processing and then cache the results, then on subsequent runs, assuming the input data is the same as before. The result will be fetched from the cache eliminating the need to process the function again.

Memoization, a concept in computer science, involves caching results to optimize system resource usage and return cached results. It helps improve performance by storing the results of expensive function calls and retrieving them when the same inputs occur again, reducing redundant computations. Learn More

The way cached data is stored is different depending on the environment Hamsters.js is running in, when running in a Web Environment the results are stored using IndexedDB. When running in Node.js the cached data is stored in an in memory data store, and is not persisted after reboots or powerloss.

You can make use of memoization by adding an extra memoize: true to your params object.

            
              function() {
                const params = {
                  array: [0,1,2,3,4,5,6,7,8,9],
                  threads: 2,
                  dataType: 'Int32',
                  sort: 'ascAlpha',
                  memoize: true
                };
                hamsters.run(params, function() {
                  params.array.forEach(function(item, index) {
                    rtn.data[index] = ((item * 120) / 10);
                  });
                }, function(results) {
                  console.log(results);
                });
              }
            
        	
  • Twitter:

  • Recent Updates

    Hamsters.js v5.6.1 Released!

    New React Native Hamsters Release v1.0.9!

    Subscribe To Updates

    Stay in the Loop! Subscribe for Updates on New Releases and Terms of Service Changes.

    © 2015 - 2024 asmithdev | All rights reserved.
    • Home
    • About
    • Privacy
    • License
    • Invest