kube/monolite

deep-equal performance benchmark

Closed this issue · 3 comments

I was wondering if you could try pulling in this deep equal function or lodash's isEqual function and see if there are any performance differences:

At the bottom of this SO thread: http://stackoverflow.com/a/6713782

Found here: https://github.com/ReactiveSets/toubkal/blob/master/lib/util/value_equals.js

I ran some tests myself.
Here is the test: https://gist.github.com/drew-wallace/2033bf6c9aedd1cfe09e78d8246949da
Here are the results of a single test run:

Test 1

  • lodash took 21.674999999999272 milliseconds: true false
  • stringify took 1192.65 milliseconds: true false
  • deepEqual took 749.0799999999999 milliseconds: true false
  • value_equal took 17.099999999999454 milliseconds: true false

Test 2

  • lodash took 27.395000000000437 milliseconds: true false
  • stringify took 1030.8950000000004 milliseconds: true false
  • deepEqual took 649.5 milliseconds: true false
  • value_equal took 17.3100000000004 milliseconds: true false

Test 3

  • lodash took 22.590000000000146 milliseconds: true false
  • stringify took 1092.255000000001 milliseconds: true false
  • deepEqual took 796.1800000000003 milliseconds: true false
  • value_equal took 16.904999999998836 milliseconds: true false

Test 4

  • lodash took 25.965000000000146 milliseconds: true false
  • stringify took 953.335000000001 milliseconds: true false
  • deepEqual took 618.0299999999988 milliseconds: true false
  • value_equal took 18.7549999999992 milliseconds: true false

Test 5

  • lodash took 21.404999999998836 milliseconds: true false
  • stringify took 1030.9050000000007 milliseconds: true false
  • deepEqual took 644.0100000000002 milliseconds: true false
  • value_equal took 8.524999999999636 milliseconds: true false

In other tests lodash would perform slower than all the others by a vast amount in Test 1 but subsequent tests showed a ramp up in performance most likely from caching the results.

I would advise switching to the value_equal or lodash isEqual functions I mentioned above for better performance.

kube commented

Thanks for your report and benchmark.

It was already planned to bundle a custom and limited deepEqual function, as most of the checks done by generic deepEqual libraries are not necessary in the context of monolite, and have a big impact on performance.

This will be the next perfomance optimization on monolite, along with the static accessor function resolution optimization once TypeScript officially provides custom AST transforms in version 2.3 (microsoft/TypeScript#13940).

kube commented

I now provide a custom deepEqual function since 76c25a8.

It's intentionally limited, and will need to be enhanced in objectEqual function performance which uses Object.getOwnPropertyNames.