FormidableLabs / react-fast-compare

fastest deep equal comparison for React
MIT License
1.59k stars 54 forks source link

Investigate Object.is() #8

Closed chrisbolin closed 6 years ago

chrisbolin commented 6 years ago

The Object.is class method is very close to === but differs in two ways:

> Object.is(NaN, NaN)
true
> NaN === NaN
false
> Object.is(+0, -0)
false
> +0 === -0
true

Benefits

Both of these are pretty minor cases

Downsides

This check doesn't come for free.

Benchmarks on node 8.3.0 using master, Object.is, and the MDN polyfill.

The native method is about 17% slower, and the polyfill is about 7.5% slower.

--- speed tests: generic usage ---

react-fast-compare x 175,552 ops/sec ±1.63% (87 runs sampled)
react-fast-compare-object-is x 146,104 ops/sec ±2.18% (85 runs sampled)
react-fast-compare-object-is-polyfill x 162,487 ops/sec ±1.62% (84 runs sampled)
  fastest: react-fast-compare

--- speed tests: generic and react ---

react-fast-compare x 140,986 ops/sec ±1.54% (85 runs sampled)
react-fast-compare-object-is x 122,360 ops/sec ±1.07% (89 runs sampled)
react-fast-compare-object-is-polyfill x 138,398 ops/sec ±1.42% (85 runs sampled)
  fastest: react-fast-compare,react-fast-compare-object-is-polyfill

Code for benchmarks is here: https://github.com/FormidableLabs/react-fast-compare/pull/9

chrisbolin commented 6 years ago

Current decision: don't use Object.is() or a polyfill; the performance losses are too much.