FormidableLabs/react-fast-compare

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

Homepage:

Size: 56

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

react-fast-compare

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.

Travis Status AppVeyor Status npm version size_minzip size_min

chart

(Check out the benchmarking details.)

Install
rn add react-fast-compare

m install react-fast-compare
Highlights
Usage
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() {
// ...


Benchmarking

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.

Generic Data
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.

React and Generic Data
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.

Running Benchmarks
rn install
rn run benchmark
License

MIT

Contributing

Please see our contributions guide.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.