Enhance the javascript performance

I think is the key point to work and support the language eco case the fact of it is single thread langue but, it is potent for the web.

I faced a situation to make a very heavy compute on the browser, so I made it on a spirited web worker. But passing the data between the main process and the web worker thread was the issue to pass more than 100 MB array of data, And access it from there.

The wrong usage I did was: pass the array and loop inside the worker.

  // out side the worker.
  let fatArray = []
  fatArray.push(veryFatData)

  // inside the worker
  fatArray.forEach()

The enhanced way: add the array elements as object properties make a huge improvement in access performance

  // out side the worker.
  let thinObject = {}
  thinObject[key] = value

  // inside the worker
  thinObject[key]

The Explain is very simple make it from O(n) to be O(1) with object hashing properties.

And that’s it.