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

Performance concerns related to translate() #71

Closed
satazor opened this issue Jan 22, 2017 · 16 comments
Closed

Performance concerns related to translate() #71

satazor opened this issue Jan 22, 2017 · 16 comments
Assignees

Comments

@satazor
Copy link
Contributor

satazor commented Jan 22, 2017

Hello!

I've been using the translate() enhancer for quite some time and, after some experiments, I concluded that all components using translate are being re-rendered after any dispatch(action).

All my components extend PureComponent which goes well with redux because it avoids re-rendering components unless props have changed. The issue here is that the p object changes every time because of this line: https://github.com/Tiqa/redux-polyglot/blob/master/src/selectors.js#L52. A new object is being created in mapStateToProps function which causes p ref to change and, consequently, causes all translated components to re-render.

The user-land solution here is to implement a custom shouldComponentUpdate function that does a shallow compare for all properties except for p, which needs to be deeply compared. While it works, it feels awkward to delegate that responsibility to devs.

Am I missing something?

@guillaumearm
Copy link
Collaborator

guillaumearm commented Jan 22, 2017 via email

@satazor
Copy link
Contributor Author

satazor commented Jan 22, 2017

@guillaumearm sounds good! I'm getting huge perf issues on inputs, where a dispatch is being issued on every keypress. Do you have some free time to solve this issue? I can step in but I guess it would take much more time to do it.

@guillaumearm
Copy link
Collaborator

ok i will publish a new release candidate tonight about this ;-)

guillaumearm pushed a commit that referenced this issue Jan 26, 2017
using createSelector, in response to #71
@guillaumearm
Copy link
Collaborator

I just published a patch on next npm dist-tag.

try it with a npm install redux-polyglot@next
and tell me if it's better ;-)

@satazor
Copy link
Contributor Author

satazor commented Jan 27, 2017

@guillaumearm I've tested the next dist tag and I see no difference. :(

@guillaumearm
Copy link
Collaborator

hum too bad.
I will write more tests about react performance soon, and find a way to solve that.
stay tuned ;-)

@guillaumearm
Copy link
Collaborator

guillaumearm commented Jan 29, 2017

@satazor,
here: https://github.com/Tiqa/redux-polyglot/blob/optimize/getP/src/selectors.js#L69
I think it's because second parameter getP object is recreated all the time.

I will try to use a memoized merge object to fix this.
what do you think ?

another solution would be to use createSelectorCreator from reselect to create a custom createSelector.

@guillaumearm
Copy link
Collaborator

guillaumearm commented Jan 29, 2017

done here : d69a9af
I just published the 0.4.2-1 version on nextnpm dist-tag ;-)

Try it, and tell me if it's better ;-)
Can you provide me your tests ? if you got some.

@satazor
Copy link
Contributor Author

satazor commented Jan 29, 2017

I'm testing on a proprietary project but it's quite simple to test, just export a translated pure component and do a console.log inside render. You will see the print everytime you dispatch something (non related to polyglot).

Thanks for this, will test in a few hours.

@satazor
Copy link
Contributor Author

satazor commented Jan 31, 2017

@guillaumearm sorry for the delay. The behavior is still the same, will try to provide a fix.

satazor added a commit to satazor/redux-polyglot that referenced this issue Jan 31, 2017
@satazor
Copy link
Contributor Author

satazor commented Jan 31, 2017

@guillaumearm I've added a test case in #75, will investigate a fix. Want to do this together? :D

@guillaumearm
Copy link
Collaborator

Yup, sure ^^
But not tonight, I'm busy
anyway, thank you very much for your help :)

guillaumearm pushed a commit that referenced this issue Feb 1, 2017
Add test for #71.

Merged on a fix/rerender branch.
@guillaumearm
Copy link
Collaborator

found it ! just need to memoize all getTranslation* functions.
I will publish a new release soon ^^

image

@guillaumearm
Copy link
Collaborator

Merged, it is seems to be OK.

@satazor you can test it on next npm dist-tag ;-)

@satazor
Copy link
Contributor Author

satazor commented Feb 19, 2017

I'm currently on my phone, but will test asap.

@satazor
Copy link
Contributor Author

satazor commented Feb 21, 2017

I confirm it's working! Thanks for fixing this!

@satazor satazor closed this as completed Feb 21, 2017
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