Skip to content
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

Question: did you benchmark it? #9

Closed
AlexGalays opened this issue Aug 12, 2019 · 4 comments
Closed

Question: did you benchmark it? #9

AlexGalays opened this issue Aug 12, 2019 · 4 comments

Comments

@AlexGalays
Copy link

Hello! the idea behind react-tracked seems interesting.

You claim the performances are better but did you actually verify that? Aren't you creating a completely new proxy on each update?

Cheers

@dai-shi
Copy link
Owner

dai-shi commented Aug 12, 2019

Hi,

The latest benchmark result at the moment is here: #1 (comment)
Compare react-tracked-useSelector and react-tracked-useTrackedState too see the tracking overhead.

creating a completely new proxy on each update

Yeah, that's the point, because we don't know when render process ends.
It's optimized with per-hook cache, so it won't create a new proxy for the same object.
This means immutable state update is important.
Related discussion: #7 (comment)

@AlexGalays
Copy link
Author

Ok thanks, guess we can close this then :)

It seems useSelector is not that much faster and is quite a bit less ergonomic, what do you think?

@dai-shi
Copy link
Owner

dai-shi commented Aug 13, 2019

Theoretically, useSelector is faster than useTrackedState if a selector is properly implemented.

The code in js-framework-benchmark is very simple and we don't see a big difference. You can see useSelector is faster in "select row."

Here's another benchmark for reactive-react-redux, as a reference.
dai-shi/reactive-react-redux#32 (comment)
Those benchmarks are with extreme usage, and especially for "stockticker" useTrackedState is slower.

In summary, useTrackedState is as fast as useSelector for most cases. In some cases, useTrackedState is slower. I don't have a benchmark, but if a developer wrote a selector improperly (which is likely), useSelector would be much slower.

@dai-shi
Copy link
Owner

dai-shi commented Aug 14, 2019

Forgot to respond this part:

less ergonomic

Totally. It should be much more intuitive for most of the cases.
Some edge cases exist, though, as written in the limitations section. It may occur if you deal with object ref equality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants