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

Canvas Performance: ComponentRendererComponent shouldUpdate() problems #6066

Closed
balazsbajorics opened this issue Jul 11, 2024 · 0 comments · Fixed by #6070
Closed

Canvas Performance: ComponentRendererComponent shouldUpdate() problems #6066

balazsbajorics opened this issue Jul 11, 2024 · 0 comments · Fixed by #6070
Assignees
Labels
Canvas Affects the visual editor Performance

Comments

@balazsbajorics
Copy link
Contributor

When resizing a PromiseCard component on the canvas,

Image

we spend 6ms on shouldUpdate inside the componentRendererComponent. Bottom up, it spends most of that time in isElementInChildrenOrPropsTree -> React.Children.toArray.

This should be blazing fast, because this is called in a very tight loop.

@balazsbajorics balazsbajorics added Canvas Affects the visual editor Performance labels Jul 11, 2024
@balazsbajorics balazsbajorics changed the title Canvas Performance: ComponentRendererComponent shouldUpdate() proeblems Canvas Performance: ComponentRendererComponent shouldUpdate() problems Jul 11, 2024
@gbalint gbalint self-assigned this Jul 11, 2024
@gbalint gbalint mentioned this issue Jul 12, 2024
2 tasks
liady pushed a commit that referenced this issue Dec 13, 2024
**Problem:**
See #6066

**Fix:**
The major contributor to the slowness of `isElementInChildrenOrPropsTree
` is `React.children.toArray`.
I tried to use `React.children.forEach` or `React.children.map` but
those just made things worse.
However, we know that in lot of cases `props.children` is just an array
of elements or a React element itself. In these cases there is no need
to run the fully general and slow toArray. Even though this is not the
official use of the API (it is actually discouraged:
https://react.dev/reference/react/Children#why-is-the-children-prop-not-always-an-array),
it makes sense to try to get the elements without calling toArray (and
we can still call `toArray` when that fails).
I made the function even more faster by switching to simple `for` loops
instead of using array functions and allocating even more arrays.
With these changes I never saw >1.3ms shouldUpdate times when resizing a
PromiseCard.

**Manual Tests:**
I hereby swear that:

- [x] I opened a hydrogen project and it loaded
- [x] I could navigate to various routes in Preview mode

Fixes #6066
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Canvas Affects the visual editor Performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants