Possible performance regression
See original GitHub issueAre you submitting a bug report or a feature request?
bug report
What is the current behavior?
I’m seeing a possible performance regression on my components because the RFF input
meta
keys are always changed at field level.
What is the expected behavior?
input
and meta
should be memoized
Sandbox Link
Here’s the component structure:
<Field
name={`${name}.enabled`}
label={i18n._(t('ui.enabled')`Ativado`)}
component={CheckBox}
/>
And this is my CheckBox component. The useCallback is to guard against the fact that input and meta seem to change on each render pass
const CheckBoxField = React.memo(
({
id,
input,
label,
required,
customError,
helperText,
disabled,
meta: { touched, error, submitError, submitFailed },
onChange,
className,
}) => {
const onChangeIt = React.useCallback(e => {
if (disabled) return;
const val = e.target.checked;
input.onChange(val);
input.onBlur();
onChange(val);
}, []);
const theError = error || submitError;
return (
<CheckBoxMat
id={id || input.name}
error={(touched || submitFailed) && (customError || theError)}
value={input.value}
onChange={onChangeIt}
label={label}
helperText={helperText}
required={required}
disabled={disabled}
className={className}
/>
);
},
);
Below is the flame graph using the shiny new React Profiler. Notice the Anonymous (Memo)
which is the CheckBoxField
component and the Checkbox (Memo)
, which is the CheckBoxMat
component, and the fact that it reports (input, meta) changed on each render pass.
What’s your environment?
RFF: 6.3.0 FF: 4.16.1 FFA: 1.1.2 Mac Os Chrome
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Perphecy: Performance Regression Test Selection Made ...
Abstract—Developers of performance sensitive production soft- ware are in a dilemma: performance regression tests are too costly to run at each commit, ...
Read more >Performance-Regression Pitfalls Every Project Should Avoid
With proper planning and execution, continuous performance-regression testing can be a powerful tool for hardware and software projects.
Read more >An Exploratory Study of Performance Regression Introducing ...
One of the most important performance issues is performance regression. Examples of performance regressions are response time degradation and increased resource ...
Read more >Performance (Regression) - RapidMiner Documentation
This operator is used for statistical performance evaluation of regression tasks and delivers a list of performance criteria values of the regression task....
Read more >Performance Regression Testing - OctoPerf
Performance Regression being a subset of regression testing as a discipline is therefore ensuring that previously developed and tested continues ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@erikras @mschipperheyn I’ve created a sandbox to demonstrate the issue https://codesandbox.io/s/react-final-form-unexpected-re-render-1hl4r?file=/src/App.js
Even though I use a
PureComponent
, the last name is re-rendered when I update the first name, because the field propsinput
andmeta
are never the same.I know I can use
subscription
onForm
and not listen forvalues
, but I still want to use it for side effects. I would expect last name not to be re-rendered if there is no change, as stated in the docs:https://final-form.org/docs/react-final-form/migration/formik
Using
subscription={{}}
onField
does not seem to have any effect on that.Am I missing something?
Turns out my key problem was onChange validation. It lead to all my fields input and meta values from updating. Yup is async and that is also a bottleneck. @erikras that (async?) onChange validation leads to all input and meta being changes seems wrong to me. Bug? I have
{ valid: true }
as a form level subscription. Perhaps that’s the reason? Super tricky to understand why things are re-rendering.