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

skip calling getRemixValidPathsGenerationContext if not in remixScene #6073

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

balazsbajorics
Copy link
Contributor

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.

image

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:

  • I opened a hydrogen project and it loaded
  • I could navigate to various routes in Preview mode

Fixes #6065

Copy link
Contributor

github-actions bot commented Jul 12, 2024

Try me

Copy link

relativeci bot commented Jul 12, 2024

#13356 Bundle Size — 62.66MiB (~+0.01%).

17ca236(current) vs 6339ece master#13355(baseline)

Warning

Bundle contains 70 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Regression 1 regression
                 Current
#13356
     Baseline
#13355
Regression  Initial JS 45.71MiB(~+0.01%) 45.71MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 21.62% 21.6%
No change  Chunks 30 30
No change  Assets 33 33
No change  Modules 4374 4374
No change  Duplicate Modules 524 524
No change  Duplicate Code 31.7% 31.7%
No change  Packages 469 469
No change  Duplicate Packages 70 70
Bundle size by type  Change 2 changes Regression 1 regression Improvement 1 improvement
                 Current
#13356
     Baseline
#13355
Regression  JS 62.65MiB (~+0.01%) 62.65MiB
Improvement  HTML 11.16KiB (-0.33%) 11.2KiB

Bundle analysis reportBranch performance/get-valid-pathsProject dashboard

}
if (isRemixScene) {
const remixPathGenerationContext = getRemixValidPathsGenerationContext(path)
if (remixPathGenerationContext.type === 'active') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hide Whitespace recommended

@balazsbajorics balazsbajorics merged commit 265b60e into master Jul 12, 2024
19 checks passed
@balazsbajorics balazsbajorics deleted the performance/get-valid-paths branch July 12, 2024 13:56
liady pushed a commit that referenced this pull request 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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Canvas Performance: useGetStoryboardRoot / getValidElementPaths performance problems
4 participants