sc0ttj / component

A tiny library for isomorphic JavaScript components
MIT License
2 stars 1 forks source link

Feature: Performance improvements #34

Closed sc0ttj closed 3 years ago

sc0ttj commented 3 years ago

There's a couple of ways that Component could possibly be made faster. This requires adding a few more functions to the codebase, which will likely increase the size from 2.2kb, to about 3kb.

Here are some of the speed and immutability improvements that can be made:

  1. Replace spread operator - stuff like { ...ob1, ...obj2 } - with one of the following "immutable object copiers":

..also look into these:

  1. Replace the Component.eq object comparison function with one of the following:

    • Note: if using mergerino, then Component.eq can simply compare prev/next states with ===
    • https://github.com/lukeed/dequal (dequal/lite is one of the very fastest around)
  2. Replace the .uid generation code with one of the following:

  3. Replace calls to native Arrays methods with these apparently faster alternatives:

  4. Memoize the "pure" functions inside Component, where possible:

  5. Optimise the validator add-on:

  6. Replace the .freeze() method with something faster:

  7. Fastest possible tweening?

  1. empty functions are fast

From https://github.com/IceCreamYou/MainLoop.js/blob/gh-pages/src/mainloop.js#L100-L103:

In all major browsers, replacing non-specified functions with NOOPs seems to be as fast or slightly faster than using conditions to only call the functions if they are specified. This is probably due to empty functions being optimized away. http://jsperf.com/noop-vs-condition