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

[icons][docs] Index search synchronously #44001

Merged
merged 2 commits into from
Oct 6, 2024

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Oct 5, 2024

I initially worked on this because it seemed to be a quick win. I couldn't believe the need in pagespeed.web.dev for the 11s of blocking time. Eleven seconds, it sounded crazy. In the timeline, there was a strange and long segment of setTimeout.

See the time it takes to see the input updated with the search term "a". I have used this as a way to measure Time To Interactive.

Before: 6.2s https://deploy-preview-44000--material-ui.netlify.app/material-ui/material-icons/?query=a
SCR-20241006-cmxo

After: 1.9s https://deploy-preview-44001--material-ui.netlify.app/material-ui/material-icons/?query=a
SCR-20241006-clwt

Help with #41126

With all the changes that we did, we are closer to the kind of performance that we had in https://v4.mui.com/components/material-icons/. We are not at Material UI v4 level yet (1.4s), but at least, with the changes that we did lately, it's not mediocre UX for developers like it was before (I'm not sure where these regressions on the icons page came from in the last 3 years, it would be interesting to debug this, we want changes to help move forward).

@mui-bot
Copy link

mui-bot commented Oct 5, 2024

Netlify deploy preview

https://deploy-preview-44001--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against c5b480f

@oliviertassinari oliviertassinari changed the title [icons] Try sync index addition [icons] Index search synchronously Oct 5, 2024
Comment on lines -543 to +545
searchIndex.addAsync(importName, searchable);
searchIndex.add(importName, searchable);
Copy link
Member Author

@oliviertassinari oliviertassinari Oct 5, 2024

Choose a reason for hiding this comment

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

The change that yields this outcome. Raised in nextapps-de/flexsearch#451.

Now, this is strange, what the async call seems to do is only https://github.com/nextapps-de/flexsearch/blob/961c3ae84a87fb3af2a52047fd7c8adc8949b86d/src/async.js#L32. So, I don't really see why 6,000 calls to setTimeout is slower. cc @romgrk if you ever seen stuff like this in the past.

Copy link
Member

@Janpot Janpot Oct 6, 2024

Choose a reason for hiding this comment

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

That whole initialization block becomes about 3 times slower for me now. It's indexing everything synchronously during module evaluation. Perhaps we can defer it as a whole? Trying a few things in #44025.

Copy link
Member Author

@oliviertassinari oliviertassinari Oct 6, 2024

Choose a reason for hiding this comment

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

That whole initialization block becomes about 3 times slower for me now. It's indexing everything synchronously during module evaluation.

@Janpot Ah, ok, this PR description wasn't super clear, I have updated it with what I was measuring. My goal was to show how time to interactive went from 6.2s to 1.9s.

It's indexing everything synchronously during module evaluation. Perhaps we can defer it as a whole? Trying a few things in #44025.

Yeah, this could be even better 👍. Overall, I find it strange that we need 700ms to index 6,000 records. This feels broken. Maybe we need a different search engine too.

Now, it's unclear to me if we need to go as far. I would be curious to merge this, wait for 30 days to see how the field vitals are and see if we need to allocate more time on this problem.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, ok, this PR description wasn't super clear, I have updated it with what I was measuring. My goal was to show how time to interactive went from 6.2s to 1.9s.

It was clear, I assume it's caused by the event loop being saturated. I just meant that the module evaluation was blocked for longer. It impacts hydration but the page should be visible because SSR.

Overall, I find it strange that we need 700ms to index 6,000 records. This feels broken. Maybe we need a different search engine too.

👍

@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Oct 5, 2024
@oliviertassinari oliviertassinari changed the title [icons] Index search synchronously [icons][docs] Index search synchronously Oct 5, 2024
Copy link
Member

@Janpot Janpot left a comment

Choose a reason for hiding this comment

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

Makes sense. One suggestion around removing a regex. I have this theory that 90% of regexes written in javascript are unnecessary 🙂.

@oliviertassinari oliviertassinari enabled auto-merge (squash) October 6, 2024 18:55
@oliviertassinari oliviertassinari merged commit 860ccd0 into mui:master Oct 6, 2024
22 checks passed
@oliviertassinari oliviertassinari deleted the search-speed branch October 6, 2024 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation package: icons Specific to @mui/icons performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants