Skip to content

Significant performance degradation when using react-final-form-arrays #22

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

Open
kavink opened this issue Feb 18, 2018 · 7 comments
Open

Comments

@kavink
Copy link

kavink commented Feb 18, 2018

I have a lot of forms in expansion panel and all of them have arrays in them. I am seeing significant performance impact . On further investigation looks like Chrome performance timeline tool is pointing towards react-final-form-arrays.es.js:289 which is significantly slowing down user experience . From the time user clicks and the changes show up on screen is a lot.

@erikras Do you have any thoughts on how I can improve the experience.

@erikras
Copy link
Member

erikras commented Feb 20, 2018

Hmm.. I hated adding that setTimeout in #4, but I didn't see any other way around the problem in final-form/final-form#26.

Perhaps it will have to be revisited and thought about some more. 🤔

@tlenclos
Copy link

tlenclos commented Dec 21, 2018

Having a big performance issue also, at least 1 second to render on input. Tried with 50 fields in my array, and each field is composed of 2 text inputs and some styled components.

Perf profile is pointing to https://github.com/final-form/react-final-form-arrays/blob/master/src/FieldArray.js#L127
(download here https://transfer.sh/xtamd/Profile-20181221T152943)

Do you have any recommendations ? How could I avoid re-rendering the whole list on user input ?

@oallouch
Copy link

same issue here

@chrismclarke
Copy link

Yes I'm trying to used posed animations and it's really bad... A list with 3 items and only a couple field still has 2+ seconds or delays and blocking

@manzoorwanijk
Copy link

Any update on this?
The performance is very poor with field array. I removed all the fields except the array field (with just two sub fields) and it is still the same.

@panfiva
Copy link

panfiva commented Apr 7, 2020

The issue has not yet been fixed (final-form-arrays-3.0.2 and react-final-form-arrays-3.1.1). The way I was able to work-around the issue is to use React.Memo to memorize the component to reduce re-rendering (props only included values that were used in rendering of ExpantionPannel

const Test3 = React.memo((props)=> {
    const classes = useStylesExpantionPanel();
    return (<React.Fragment>
        <ExpansionPanel>
          <ExpansionPanelSummary  expandIcon={<ExpandMoreIcon />} >
            <Typography className={classes.heading}>Title</Typography>
          </ExpansionPanelSummary>
          <ExpansionPanelDetails>
            <TextInput source={`${props.source}.minWidth`} label="Min width" resettable />
            <TextInput source={`${props.source}.maxWidth`}  label="Max width" resettable />
            <TextInput source={`${props.source}.minHeight`} label="Min height" resettable />
            <TextInput source={`${props.source}.maxHeight`}  label="Max height" resettable />
            <TextInput source={`${props.source}.width`} label="Width" resettable />
            <TextInput source={`${props.source}.height`} label="Height" resettable />
          </ExpansionPanelDetails>

        </ExpansionPanel>
      </React.Fragment>
    );
  },
  (prevProps, nextProps)=> {console.log({prevProps, nextProps}); return _.isEqual(prevProps, nextProps)}
)

This way, when other form control are updated using user input, no re-rendering is taking place since this form is not re-rendered.

@ptumbra
Copy link

ptumbra commented Apr 19, 2021

The project I'm working on has some large forms with dynamically generated nested field arrays so I figured I'd throw my experience out there in case it helps others. We were able to signifcantly improve overall form performance by setting the subscription and validateField props on appropriate elements. Out of the box final-form can re-render the form and individual fields a lot. That usually isn't a problem until you add arrays, nesting, or a lot of fields.

A couple of quick examples:

  • Setting the subscription prop on the Form can significantly reduce the number of form-level re-renders. Try to set the subscription scope as narrow as possible. <Form subscription={{ submitting: true }}>
    See: final form subscription example
  • Setting the validateField props on most fields was highly effective for us because it cuts down on cross-field validation and in the vast majority of cases validating a single field does not require the immediate validation of another. <Field name="name" validateFields={[]}>
    See: validateFields
  • Adding memoization of components rendered inside a FieldArray helps prevent useless rendering of array children (and the cascading effect if you have nested arrays)
  • Some of our team members had a misunderstanding of how the Field component prop worked and were passing inline functions to them. The component prop is using React.createElement under the hood and causes this to be recreated on every render which is obviously very expensive. Switching most Field definitions to use children was beneficial here.

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

8 participants