Name: react-fast-compare
Owner: Formidable
Description: fastest deep equal comparison for React
Created: 2018-04-10 18:33:39.0
Updated: 2018-05-14 15:55:47.0
Pushed: 2018-04-18 22:17:26.0
Size: 56
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
The fastest deep equal comparison for React, perfect for
shouldComponentUpdate
, also really fast at general-purpose deep comparison.
This is a fork of the brilliant
fast-deep-equal with some
extra handling for React.
(Check out the benchmarking details.)
rn add react-fast-compare
m install react-fast-compare
t isEqual = require('react-fast-compare');
eneral usage
ole.log(isEqual({foo: 'bar'}, {foo: 'bar'})); // true
eact usage
s ExpensiveRenderer extends React.Component {
ouldComponentUpdate(nextProps) {
return !isEqual(this.props, nextProps);
nder() {
// ...
All tests carried out locally on a MacBook. The absolute values are much less important than the relative differences between packages.
Benchmarking source can be found here. Each “operation” consists of running all relevant tests. The React benchmark uses both the generic tests and the react tests; these runs will be slower simply because there are more tests in each operation.
t-fast-compare x 161,872 ops/sec ±1.18% (82 runs sampled)
-deep-equal x 159,889 ops/sec ±1.62% (85 runs sampled)
sh.isEqual x 30,750 ops/sec ±2.02% (86 runs sampled)
-equal x 35,608 ops/sec ±1.55% (86 runs sampled)
low-equal-fuzzy x 94,141 ops/sec ±1.80% (89 runs sampled)
stest: react-fast-compare,fast-deep-equal
react-fast-compare
and fast-deep-equal
should be the same speed for these
tests; any difference is just noise. react-fast-compare
won't be faster than
fast-deep-equal
, because it's based on it.
t-fast-compare x 150,667 ops/sec ±1.86% (83 runs sampled)
-deep-equal x 510 ops/sec ±1.67% (77 runs sampled)
sh.isEqual x 25,760 ops/sec ±1.63% (83 runs sampled)
-equal x 629 ops/sec ±2.43% (80 runs sampled)
low-equal-fuzzy x 454 ops/sec ±1.42% (79 runs sampled)
stest: react-fast-compare
Three of these packages cannot handle comparing React elements (which are
circular): fast-deep-equal
, nano-equal
, and shallow-equal-fuzzy
.
rn install
rn run benchmark
Please see our contributions guide.