-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
try faster shallowEqual #17
Conversation
} | ||
node[path[lastIndex]] = EDGE; | ||
} | ||
return root; // FIXME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This FIXME comment was there because I thought you don't want to use weakMemoizeArray
but something like weakMemoizeObject
which can eliminate if (old.length === arg.length) {
check.
If it's not a big issue, please just remove the FIXME comment.
) { | ||
continue; | ||
const root = memoizedBuildTrie(locations); | ||
const walk = (la, lb, node) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can define walk
outside of proxyShallowEqual
which gives me better benchmark result. @theKashey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you deal with differ.unshift(item);
in walk?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a global variable. Actually I should also extract run
, to keep function as simple as possible.
proxyequal 2.0.6 proxyEqual
proxyequal 2.0.6 proxyShallowEqual
proxyequal fa66cca proxyShallowEqual
I short, it's hard to tell which is better than others, but generally all are good. |
🙅♂ current proxyShallowEqual is overall better for worst cases. |
proxyequal fa66cca proxyShallowEqual
proxyequal 1c08661 proxyShallowEqual
Basically you should expect around 5% error rate. |
Results for |
From: dai-shi/reactive-react-redux#3 (comment) Trying it. proxyequal 1c08661 proxyShallowEqual
proxyequal 7c751f2 proxyShallowEqual
|
But you lost "last affected" optimization. Even without it - results looking great(same). |
I wasn't pretty sure if it's effectively implemented. Is keeping referential equality of trie important? |
...no, it's no longer needed. You are right. |
Changing I guess the stockticker benchmark is faster with proxyEqual because of collectValuables. |
proxyequal fd7533a proxyShallowEqual
Stockticker is improved, more than 2.0.6 proxyEqual, but others are dropped. This might require referential equality of trie, which is not implemented yet. (my naive trial was failed...) |
To use trie more efficient in reporting, we may need to pass parent node (or old and new nodes) in onKeyUsage instead of suffix. This would require too much refactoring and it might not work. |
proxyequal fd7533a proxyShallowEqual
proxyequal e7f0ad0 proxyShallowEqual
proxyequal c78198a proxyShallowEqual
|
Results are almost identical. |
|
It's hard to compare two different versions of
shallowEqual
.I've tried 6 cases(3 x with/without memoization)
Roughly - it has a simpler comparison loop, and preparation loop is also just O(n), while old sorting is more or less unpredictable.
All tests are green, but I would like to double check from you, that your tests are also green.