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: useGetStoryboardRoot / getValidElementPaths performance problems #6065

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

Comments

@balazsbajorics
Copy link
Contributor

When resizing a PromiseCard, it takes 7-8 ms to run useGetStoryboardRoot / getValidElementPaths which seems to spend most of its time on Remix matchRoutes.

Sounds like for every frame we repeat a task that should only be done whenever the routing configuration changes.

@balazsbajorics balazsbajorics added Canvas Affects the visual editor Performance labels Jul 11, 2024
@balazsbajorics balazsbajorics self-assigned this Jul 12, 2024
balazsbajorics added a commit that referenced this issue Jul 12, 2024
…#6073)

**Problem:**
When resizing a PromiseCard, it takes 7-8 ms to run useGetStoryboardRoot
/ getValidElementPaths which seems to spend most of its time on Remix
matchRoutes.

**Diagnosis:**
Turns out, we had this three lines of code running for _every single
element visited_ during the recursive `getValidElementPathsFromElement`
walk:
```    
const isRemixScene = isRemixSceneElement(element, filePath, projectContents)
    const remixPathGenerationContext = getRemixValidPathsGenerationContext(path)
    if (remixPathGenerationContext.type === 'active' && isRemixScene) {
```
`getRemixValidPathsGenerationContext` is not trivially cheap to call,
and it only returns a sensible result if `path` points at a remix scene.

**Fix:**
Only call getRemixValidPathsGenerationContext if `isRemixScene` is true.

Now `useGetStoryboardRoot` only takes 0.7ms instead of 7ms.

<img width="120" alt="image"
src="https://github.com/user-attachments/assets/750c33ac-13e1-43fd-90d1-200439ab5708">

**Note:** 0.7ms still feels excessive to run on every single frame, I'll
continue the investigation and make a follow up PR

**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 #6065
liady pushed a commit that referenced this issue Dec 13, 2024
…#6073)

**Problem:**
When resizing a PromiseCard, it takes 7-8 ms to run useGetStoryboardRoot
/ getValidElementPaths which seems to spend most of its time on Remix
matchRoutes.

**Diagnosis:**
Turns out, we had this three lines of code running for _every single
element visited_ during the recursive `getValidElementPathsFromElement`
walk:
```    
const isRemixScene = isRemixSceneElement(element, filePath, projectContents)
    const remixPathGenerationContext = getRemixValidPathsGenerationContext(path)
    if (remixPathGenerationContext.type === 'active' && isRemixScene) {
```
`getRemixValidPathsGenerationContext` is not trivially cheap to call,
and it only returns a sensible result if `path` points at a remix scene.

**Fix:**
Only call getRemixValidPathsGenerationContext if `isRemixScene` is true.

Now `useGetStoryboardRoot` only takes 0.7ms instead of 7ms.

<img width="120" alt="image"
src="https://github.com/user-attachments/assets/750c33ac-13e1-43fd-90d1-200439ab5708">

**Note:** 0.7ms still feels excessive to run on every single frame, I'll
continue the investigation and make a follow up PR

**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 #6065
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.

1 participant