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

[Bug]: Clicking on the first plan takes a long time to load #168

Closed
1 task done
ZzRanger opened this issue Sep 13, 2022 · 8 comments
Closed
1 task done

[Bug]: Clicking on the first plan takes a long time to load #168

ZzRanger opened this issue Sep 13, 2022 · 8 comments

Comments

@ZzRanger
Copy link
Contributor

What did you expect to happen?

I expect the degree planning tool to immediately load after clicking on a plan.

What happened?

ezgif-1-01d169a597

Version

Beta 0.1.0

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ZzRanger ZzRanger added Type: Bug Report Status: Awaiting Triage Requiring a determination on how to proceed and removed Status: Awaiting Triage Requiring a determination on how to proceed labels Sep 13, 2022
@akevinge
Copy link
Member

For some reason the response is 4MB compressed and 40MB decompressed.
image

The production builds are completely fine. I ran this analyzer on the build, and the bundle size is completely normal. Compressed bundle size on the server is about 100KB and on the client is 500KB.

The issue seems to be that MUI isn't being tree-shaken for some reason (see .next/trace). Seems there are many top-level imports for @mui/material and @mui/icons-material throughout the code, so that's probably why.

@ZzRanger
Copy link
Contributor Author

Nice analysis! This is something we would like to optimize sometime in the future. If you are interested in working on this let me know and I can assign this to you.

@akevinge
Copy link
Member

akevinge commented Sep 18, 2022

hey @ZzRanger,

I wouldn't mind working on this issue.

If it is an issue of top-level imports, I'm not really sure why it doesn't occur in production build. I would imagine tree-shaking would be the same for production and development, but I honestly don't know what the default configuration is. I didn't look that closely, but maybe the production build is just as unoptimized but the compression hides any noticeable lag? I'll look into it.

Side note: I just realized that 500KB is also pretty big

@ZzRanger
Copy link
Contributor Author

Per discussion at 9/20 meeting, we'll be tabling this issue for now.

@ZzRanger
Copy link
Contributor Author

ZzRanger commented Oct 3, 2022

Linking #118 #156 and by extension #216, as we can look to optimize loading time of Credits page as well. I have some intuition on how to do it (potentially load components after initial page load through some useEffect magic) but will need further discussion.

@ZzRanger ZzRanger moved this from Stuck to Staged in Planner Maintainer Current Tasks Oct 3, 2022
@akevinge
Copy link
Member

akevinge commented Oct 16, 2022

So after taking a good look at the bundle size, there are 3 culprits of the large bundle size.
image

Redux looks really big, but it's actually its usage of Firebase which is discussed later.

courses.json

This file is really huge. We could get rid of it and use Next's API routes or a Firebase cloud function instead. Not sure if the latency of the request is better than loading it in the bundle, but we could give it a show.

Mui

After a good amount digging, I discovered that Next supports transforming imports via SWC, which would allow Webpack to properly tree shake MUI.

However, we are currently using Next v12.1 and import transform was added afterwards see here. This would require us to update to v12.2.6, which does NOT include breaking changes for us.

Upgrading to v12.2.6 and taking advantage of import modularization allows us to go from compiling 11k to 1k modules, which is noticeably faster in the development environment and marginally faster in production.

With v12.2.6 import modularization:
image

Without import modularization:
image

Firebase

Firebase is an absolute tank (113KB + unknown size when used in Redux) and is loaded on every single page. Unfortunately, we are using v8.4.1, while tree shaking in only supported v9+ see here.

akevinge added a commit to akevinge/planner that referenced this issue Oct 16, 2022
akevinge added a commit to akevinge/planner that referenced this issue Oct 16, 2022
BREAKING CHANGE: Update Next v12.1 -> v12.2.6, use SWC modularize imports, add
bundle analyzer. See:
UTDNebula#168 (comment)

UTDNebula#168
@ZzRanger
Copy link
Contributor Author

Nice work! 2020-courses.json was meant to be a temporary solution until the API goes live so we're planning on removing it anyway once we integrate Nebula API.

Regarding MUI & Firebase, I'm cool with upgrading Next & Firebase sometime after beta launch.

@sarthak22gaur
Copy link
Contributor

There are a lot of perf improvements that can be done in this.

  1. We can get away with almost 90% of the redux store by using SSR and caching query data.
  2. The courses list can be cached as well quite easily
  3. Defining better suspense boundaries will greatly increase the UI/UX experience in terms of loading times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants