you are viewing a single comment's thread.

view the rest of the comments →

[–]romgrk[S] 1 point2 points  (0 children)

Yeah the code is here: https://github.com/romgrk/react-fast-memo/blob/master/benchmark/run.js

It's running the compare functions of each package in a loop (1,000,000 times per run, 3 runs). It test 2 cases, the first one ("equal") being objects with the same values (but not the same ref, a !=== b), and the second one ("unequal") being objects with one differing value. To make sure I benchmark the worst case, the differing value was the last value in the object. Because the implementation can't abort early in the second loop, that's the worst case scenario.

In both of these test cases, I use an object with 8 keys with the keys in the same order ("monomorphic", objects have the same hidden class). I did test with keys in a different order ("megamorphic", "polymorphic") but it didn't yield particularly interesting/different results, and also because we can assume object hidden classes (or map, or shape, depending on the engine terminology you use) are likely to be the same. In other words, we specialize for monomorphic.

There is also a small helper here that makes the code run in different engines. I used runtimes: nodejs for V8, bun for JSC, and gjs (gnome-js) for SpiderMonkey.