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 optimizations #54

Closed
aduth opened this issue Mar 8, 2016 · 11 comments
Closed

Performance optimizations #54

aduth opened this issue Mar 8, 2016 · 11 comments

Comments

@aduth
Copy link

aduth commented Mar 8, 2016

Loving this component so far! However, in my own usage, and even in the demo site, there's a noticeable lag when attempting to enter text into fields at a reasonable typing speed. Enabling the "trace react updates" option in Chrome React Developer Tools, it becomes apparent that the entire form is re-rendered any time an input changes.

render

I haven't dug into the code, but it would seem reasonable to implement shouldComponentUpdate (perhaps simply with pure-render-mixin) to prevent rerendering of components not affected by the change in form values.

@Natim
Copy link
Contributor

Natim commented Mar 8, 2016

Thank you for this report 👍

@n1k0
Copy link
Collaborator

n1k0 commented Mar 9, 2016

If we want to properly implement shouldComponentUpdate, we'll have to rely on some immutable library like Immutable.js, which was something I tried to avoid.

But I agree the impact on performances on lower end machines might get really important, so we should do this upgrade.

(And yeah, kudos for the super clean and useful report.)

@aduth
Copy link
Author

aduth commented Mar 9, 2016

If we want to properly implement shouldComponentUpdate, we'll have to rely on some immutable library

Again, pardon my ignorance of the codebase and whether these suggestions have already been considered, but it's quite possible to perform shallow comparison (i.e. pure render) even with plain object properties, so long as you're careful not to mutate the original when updating.

Object.assign( {}, original, { input: 'New Value' } );

Or, for deeply nested objects, consider pulling in lodash.merge (available as standalone package):

merge( {}, original, { foo: { bar: { input: 'New Value' } } } );

@n1k0
Copy link
Collaborator

n1k0 commented Mar 10, 2016

The problem is not with copying/merging deeply nested objects, it's with comparing them to know if they've changed.

({a: 1, b: {c: 2}}) === ({a: 1, b: {c: 2}}) // false

And shouldComponentUpdate needs to return a boolean to trigger a render when things have changed. So we need immutable data structures which don't carry identity as plain js objects do, so we can safely compare them and return the appropriate boolean value there.

Am I missing something obvious? I didn't have my first coffee of the day just yet.

@leplatrem
Copy link
Contributor

Does this affect the demo only or the form rendering itself?

@aduth
Copy link
Author

aduth commented Mar 17, 2016

@leplatrem : I'm observing it in my own usage as well, but the demo was the easiest way for me to illustrate the problem.

@magopian
Copy link
Contributor

It may be related to kinto-admin, but when viewing a page with a few hundred records (for the blocklist), the page is very laggy, unresponsive, and even freezes for a couple of seconds at the beginning.

@aduth
Copy link
Author

aduth commented Mar 17, 2016

Might be compounded with the fact that JSON schema validation is performed on every change:

https://github.com/mozilla-services/react-jsonschema-form/blob/afcb38e/src/components/Form.js#L51

@n1k0
Copy link
Collaborator

n1k0 commented Mar 17, 2016

This is probably the very first thing to investigate as a solution https://facebook.github.io/react/docs/shallow-compare.html

@yogeshwar-woodside
Copy link

yogeshwar-woodside commented Nov 19, 2024

Hello, I am experiencing this issue with v4 and it is causing performance bottleneck in react-native mobile app.

It appears that entire form re-renders on ANY field change.
We are particularly having large forms (90+ fields), and expected to have larger and complex forms in future.

How can this be improved?
Is there any way in which only affected fields are re-rendered instead of entire form?

I have carried out the experiment using v5.
It's evident form the screenshot that Form element re-rendered for every character entered in last name. 9 chars = 9 renders

image

@Sushil3663
Copy link

I have used a custom debounce of 2 seconds in onChange to improve type speed as a temporary solution
--- const debouncedOnChange = useDebounce(onChange, 2000);

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

7 participants