FormidableLabs / react-fast-compare

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

Idea: cache results in WeakMap #29

Closed natew closed 4 years ago

natew commented 6 years ago

This could avoid a ton of traversing potentially. Not sure if it's actually a good idea, so opening here for comments but if it is, I'd happily take a stab at it.

Basic idea is if you to save large objects being compared all the time (think fast re-renders with objects), this would use WeakMap.set(objA, aID), and WeakMap.set(objB, bID) and then separately store (aID => bID => true/false). Sound right?

theKashey commented 6 years ago

Used this approach once - works well, no issues or speed concerns.

chrisbolin commented 6 years ago

@natew very good idea! i would however like this project to closely mirror fast-deep-equal; they can make it really fast, and we can make it work with React. Have you pitched them the idea?