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

perf(form): improve form state reconciliation #5269

Merged
merged 2 commits into from
Nov 24, 2023

Conversation

bjoerge
Copy link
Member

@bjoerge bjoerge commented Nov 24, 2023

Description

This fixes a couple of perf related issues.

  1. 3ada485 – When traversing over the previous + next formState to see what values are unchanged, we previously had a circular reference detection that added parents to a set as it went over it. When arriving at a node that's in the set of parents, it will short-circuit and return the next value. After done traversing over a subtree, the parent was still kept around in the set, which made it appear in parents of sibling subtrees, sometimes short-cirquiting (and returning the next) value in cases where it could have re-used the previous value (by referential identity). This PR fixes the issue by removing a node from parents after done iterating over a subtree.
  2. d9f22ba – Fixing the above revealed that we had another issue introduced by adding _allMembers to formstate (introduced by refactor(form): fix issue with hiding a field group that only have fieldsets #4477), causing the reconciliation to become super slow. This fixes the issue by making _allMembers non-enumerable, which prevents immutableReconcile from iterating over it.

What to review

  • This should fix an issue that could sometimes produce different value identities for form state nodes that are identical between renders

Notes for release

  • N/A internal (although it likely has a noticeable impact on editing performance)

Copy link

vercel bot commented Nov 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview Nov 24, 2023 11:08am
test-studio ✅ Ready (Inspect) Visit Preview Nov 24, 2023 11:08am
1 Ignored Deployment
Name Status Preview Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Nov 24, 2023 11:08am

@bjoerge bjoerge changed the title perf(improve) form state reconciliation perf(form): improve form state reconciliation Nov 24, 2023
Copy link
Contributor

No changes to documentation

Copy link
Contributor

Component Testing Report Updated Nov 24, 2023 11:14 AM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 17s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 3s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 8s 3 0 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 6s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 16s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 8s 9 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 38s 18 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 6s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 3s 3 0 0

Copy link
Member

@skogsmaskin skogsmaskin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! 👍

I have tested this code against the issue I have been experiencing related to this (reconciling portable text member items), and this solves those issues!

@bjoerge bjoerge added this pull request to the merge queue Nov 24, 2023
Merged via the queue into next with commit a0f93cb Nov 24, 2023
38 checks passed
@bjoerge bjoerge deleted the perf/improve-immutable-reconcile branch November 24, 2023 13:43
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

Successfully merging this pull request may close these issues.

2 participants