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

Effect on JupyterLab bundle size #1873

Closed
vidartf opened this issue Nov 5, 2019 · 11 comments · Fixed by #2103
Closed

Effect on JupyterLab bundle size #1873

vidartf opened this issue Nov 5, 2019 · 11 comments · Fixed by #2103
Milestone

Comments

@vidartf
Copy link

vidartf commented Nov 5, 2019

Hi!

I've been looking at the effect of the plotly jupyterlab extensions on the final bundle size, and I've made these observations:

  • The plotly.js part for a prod build is roughly 17 MB.
  • Both plotly.js/dist/plotly.js and plotly.js/dist/plotly.min.js gets included in the final lab bundle (one from plotlywidget and one from jupyterlab-plotly). Both end up taking roughly equal amount of space (6-7 MB) when the lab build is run in prod mode.
  • Also some parts of the plotly.js/src dir gets included (from plotlywidget).

Would it be possible to consolidate the imports in the jupyterlab packages such that only one of the dists gets imported from (and if possible also the src import)?

@nicolaskruchten
Copy link
Contributor

Yikes, we should be using the min version everywhere for sure. The duplication is a bummer.

@jonmmease could we imagine merging these extensions someday?

@jonmmease
Copy link
Contributor

could we imagine merging these extensions someday?

Yes, and we almost did for v4. But the distinct plotlywidget package is needed in order for nbviewer to find the extension, and I didn't spend enough time on it to figure out how to combine things in such a way that wouldn't break something 🙂

@nicolaskruchten
Copy link
Contributor

Ah right. Does JLab have a way for extensions share dependencies yet that we know of?

@vidartf
Copy link
Author

vidartf commented Nov 6, 2019

The packages doesn't need to be merged to resolve this, they just need to import from the same dist. If the dependency versions are compatible, jupyterlab will de-duplicate them.

@vidartf
Copy link
Author

vidartf commented Nov 6, 2019

Note: even now the dependency package is already de-duplicated, but the code is duplicated in the final bundle since it is imported from two different dists.

@nicolaskruchten
Copy link
Contributor

Ah nice. So if we changed https://github.com/plotly/plotly.py/blob/master/packages/javascript/plotlywidget/src/Figure.js#L5 to load the unminified bundle and not from src then in principle webpack should dedupe and minify all of Plotly. We'll try! Probably for 4.4 :)

@vidartf
Copy link
Author

vidartf commented Nov 7, 2019

Sounds like a plan. Please ping this issue with any progress, and I'll be happy to verify if it works :)

@nicolaskruchten
Copy link
Contributor

So I'm trying to tackle this and having some problems... I've uninstalled and reinstalled both extensions from NPM and right now my vendor bundle sits at 11MB which is smaller that I would expect. I'm also having trouble analyzing it to understand what's in it... @vidartf how were you able to determine that Plotly is in there twice?

@nicolaskruchten
Copy link
Contributor

Is there a way to jupyter lab build such that it outputs the webpack bundle analyzer stats?

@nicolaskruchten
Copy link
Contributor

Some data from ls ~/miniconda2/envs/dash/share/jupyter/lab/static

Base install - 4.4 MB vendor file

JupyterLab v1.2.0
Known labextensions:
   app dir: /Users/nicolas/miniconda2/envs/dash/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v1.1.0  enabled  OK
        jupyterlab-jupytext v1.1.1  enabled  OK

With jupyterlab-plotly from NPM - 7.7MB

JupyterLab v1.2.0
Known labextensions:
   app dir: /Users/nicolas/miniconda2/envs/dash/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v1.1.0  enabled  OK
        jupyterlab-jupytext v1.1.1  enabled  OK
        jupyterlab-plotly v1.4.0  enabled  OK

With jupyterlab-plotly and plotlywidget from NPM - 11MB

JupyterLab v1.2.0
Known labextensions:
   app dir: /Users/nicolas/miniconda2/envs/dash/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v1.1.0  enabled  OK
        jupyterlab-jupytext v1.1.1  enabled  OK
        jupyterlab-plotly v1.4.0  enabled  OK
        plotlywidget v1.4.0  enabled  OK

... OK so definitely there's less deduplication happening here than we'd like ;)

@nicolaskruchten
Copy link
Contributor

OK so my PR #2103 seems like the lightest touch solution to this problem, to me... I can get the bundle size to 7.6MB down from 11MB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants