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

jupyter-ai slows down initial page load significantly by downloading 4MB of icons it does not need #1221

Closed
krassowski opened this issue Feb 1, 2025 · 6 comments · Fixed by #1225
Assignees
Labels
bug Something isn't working

Comments

@krassowski
Copy link
Member

Description

This is because of dependency on @mui/icons-material and lack of any control what of it gets included.

Reproduce

Image

Image

Image

Expected behavior

jupyter-ai does not stall opening JupyterLab nor Jupyter Notebook

Context

  • JupyterLab version: 4.3.x
@krassowski krassowski added the bug Something isn't working label Feb 1, 2025
@krassowski
Copy link
Member Author

krassowski commented Feb 1, 2025

There is 16 icons from @mui/icons-material in use:

import {
Download,
FindInPage,
Help,
MoreHoriz,
MenuBook,
School,
HideSource,
AutoFixNormal
} from '@mui/icons-material';

import {
Edit,
DeleteOutline,
Cancel,
Check,
Visibility,
VisibilityOff
} from '@mui/icons-material';

import SettingsIcon from '@mui/icons-material/Settings';
import WarningAmberIcon from '@mui/icons-material/WarningAmber';

Half of these are already available in JupyterLab core (Download, Cancel, Edit, Settings, Check, Warning, Help). Using icons from core and adding SVG for icons which are not in core would probably be the best for performance.

In any case we do not need to fetch ~2200 icons.

@krassowski
Copy link
Member Author

Also one can verify that this is issue in how jupyter-ai is compiled by downloading the source or wheel from https://pypi.org/project/jupyter-ai/2.29.0/#files and analyzing the size of the unpacked archive (yes, after compression it is smaller, but unpacked it is 6MB):

Image

@krassowski
Copy link
Member Author

The solution is to either configure tree-shaking (not sure what is wrong with webpack config here), or to use path imports instead of top-level imports, see:

Of note, I already put path imports in jupyter-ai/packages/jupyter-ai/src/components/chat-settings.tsx but these need to be used everywhere.

@krassowski
Copy link
Member Author

to either configure tree-shaking (not sure what is wrong with webpack config here),

Ah, it seems like maybe nothing is wrong in config, webpack just does not shake with module federation, unless it is tricked into doing that with using a dummy shared package as described in: webpack/webpack#12532

@dlqqq
Copy link
Member

dlqqq commented Feb 3, 2025

Thanks for reporting this! I didn't know that Webpack doesn't tree shake when module federation is used. I think we need to first add a CI step that fails when importing from @mui/icons-material instead of @mui/icons-material/XYZ. Even if we manually update all MUI imports to be path imports today, our bundle size could easily be inflated by an accidental change from a new contributor.

It's unlikely that I will find the time to dive deep into this. @krassowski Do you have any suggestions on how we can enforce path imports?

@krassowski
Copy link
Member Author

I looked into some alternatives, like using babel-plugin-import (requires setting up babel in addition to TS), using a typescirpt plugin (there is a few repos with import path transformers but nothing which would work out of the box for this use case; I wrote TypeScript transformers before and will only write another one if someone sponsors it - there is just a lot of edge cases to handle, not to mention that TypeScript still does not have an public entry point for transformers in tsc config see microsoft/TypeScript#14419).

So yes, probably using eslint to enforce path imports with no-restricted-imports would be best for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants