-
Notifications
You must be signed in to change notification settings - Fork 93
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
Reduce bundle size, add code splitting #1116
base: master
Are you sure you want to change the base?
Reduce bundle size, add code splitting #1116
Conversation
We are not on Vue 3 but Vue 2. Thus the prefetch might not (yet) be implemented.
I tree shaking not done/present ATM? Moving other (sub-) components (like the Markdown editor/parser) to their own chunk might be a good option. |
I know. It's supposed to be automatic in Vue 3. As far as I understand, you're supposed to be able to manually enable it for any framework with those webpack magic comments. It's a webpack feature, so it should be independent of the Vue version. I am not sure why it's not working.
The auto-generated chunk names are very long, like I will try to move out the markdown editor. |
2c18642
to
ccdc8e6
Compare
I moved I also implemented my own
Edit: I just rebased after the merge of #1105 and we are down another 0.2 MB. |
1597111
to
9db78de
Compare
5c13db3
to
2c9bb94
Compare
I think this PR is ready for review. Unfortunately, the way in which the bloat has to be stripped from some libraries requires hacks like this. This makes it possible for one of these changes to cause unexpected breakage. I tried to test as best as I could, but I would appreciate if somebody else could take a look too to double check. I have manually tested:
Also, I copied and modified |
Man, you ran me over with that one.
I feel a bit overwhelmed and also not qualified enough to oversee all things here. Looks like magic to me currently. (Maybe a bit more sleep might help 😉.) Would you @seyfeb consider having a look at this once? I can click around a bit and see if there is some problem with anything I can see. However, this will be only of limited outcome.
The license should be ok if the upstream is GPL. I would find it very important if this were at least offered upstream. This thing with the source version sounded to me like the best solution but I am completely lost how this would be achieved with |
I can try to have a look! |
Maybe I can summarise the changes:
|
Not sure if this was introduced with this PR and/or if it's an artifact of my local dev machine but when starting from a clean installation (no recipes) and reload the cookbook page I get an error logged (not always the same, but only one per reload). The issue seems to occur while loading the chunks with webpackPrefetch annotation!?
```
ChunkLoadError: Loading chunk vendors-node_modules_nextcloud_vue_dist_Components_Multiselect_js failed.
(error: http://localhost:8000/apps/cookbook/js/cookbook-vendors-node…vue_dist_Components_Multiselect_js.js?v=e91c46ff305fc2da743a)
j jsonp chunk loading:27
e ensure chunk:6
e ensure chunk:5
component index.js:11
Oe vue-router.esm.js:2144
ze vue-router.esm.js:2171
ze vue-router.esm.js:2171
ze vue-router.esm.js:2170
Oe vue-router.esm.js:2106
g vue-router.esm.js:2362
o vue-router.esm.js:2087
o vue-router.esm.js:2091
De vue-router.esm.js:2095
confirmTransition vue-router.esm.js:2392
transitionTo vue-router.esm.js:2260
init vue-router.esm.js:2996
beforeCreate vue-router.esm.js:1298
VueJS 4
main.js:66
main.js:72
main.js:72
```
|
This could be due to the fact that you are running (like me) from the |
Your right, the path is wrong, didn't notice the apps vs custom_apps directory issue. I saw the files in the js/ folder and was wondering why they couldn't be loaded. How did you setup the build to use the correct custom_apps path, @christianlupus ? |
I did not test yet. I think, we might need to add something like __webpack_public_path__ = linkTo('cookbook', 'js') in the This was the reason for 48188dc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not go through each line, but in general it looks good to me.
One thing that bothers me, is the SimpleActionInput. I (hopefully) does the same thing as Nextcloud's ActionInput, but cannot do more than the way it is currently used. Using more functionality would require reimplementing or copying stuff over from the original component. Drawbacks are: It is a very crowded file, because lots of previously imported stuff (styles and JS) were copied into the single file; it needs to be maintained by ourselves instead of relying on a separately maintained component.
Afaik, the main reason to use this, was to reduce the bundle size. How much does the change to using the component actually save?
Thanks for reviewing it @seyfeb
Correct. The savings is about 750kB.
The reason is that
I agree. I don't love this solution either. In my opinion, 33% savings is worth it. One easy thing that I think actually has a chance of being upstreamed is to use dynamic |
Okay that's actually a lot more than suspected! This might indeed be worth the trouble (you already did the most work anyway). If you see dynamic imports as a better solution, you may change this, but either way I'm fine with the PR |
Would you prefer the dynamic import version for our own use or would it only be to upstream it and remove our own custom thing? I think we should keep |
I'm okay with that :) |
What did you do, @seyfeb, to get it running? This patch was not yet included, am I wrong? |
Naah, because I hacked it in there to get it running on my local machine. I did override the config of the
|
This is not good. It will break any other installation without the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the path where the parts are loaded generic and independent of the storage path of the app.
PS: This is just to prevent accidental merging
It's only an issue if you manually add it to custom_apps though? apps installed to apps/ (via the app store) should just work, no? |
Unfortunately no. In the official admin documentation of the server explicitly allows to have different storage locations for apps. I guess that many have the default prefix of apps but this is just a guess. For sure, this will not be working well in the other cases. |
I see. I'm a bit confused, but what seems to be working is setting
in I'm not sure if this makes sense. |
With my approach described above I'm seemingly on the good side of things. (Firefox on macOS) Although I just noiticed, the search is not working for some reason. It switches to the search page, and the data JSON data is received, but it seems not to be loaded into the component. Another note: It, e.g., does not load |
Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
`en` is the default and cannot be dynamically loaded Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
These are not needed with SimpleActionInput Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
We don't depend on moment directly, but rather @nextcloud/moment Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
The semicolon is needed here because the line below starts with (. JavaScript will attempt to call the line that now has a semicolon as a function. Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
I forgot why I changed this to be honest. Signed-off-by: Marcel Robitaille <[email protected]>
058a83b
to
3febd8f
Compare
I'm writing this as a PR only so you can see the code changes. I don't intend this to be merged as is. I am just trying to continue the code splitting discussion.
Fixes #455
Fixes #1109
I implemented "naive" code splitting. I say naive because I just did every different route. However, these routes are usually quite small. We might be better off including the truly tiny ones in the main bundle to minimize the number of network requests.
Here is the bundle analyzer for the
master
branch.cookbook-main.js
is 4.79 MB raw, 1.05 MB gzipped.cookbook-guest.js
is 1.06 MB raw, 277 kB gzipped.This small change seems to have inadvertently split some node modules into their own chunks. Now we have:
cookbook-main.js
3.67 MB raw, 872 kB gzippedcookbook-guest.js
1.06 MB raw, 277 kB gzipped.moment
711 kB raw, 112.97 kB gzippedRecipeView.js
87 kB raw, 16 kB gzippedMultiselect.js
173 kB raw, 45 kB gzippedRecipeList.js
63 kB raw, 13 kB gzippedRecipeEdit.js
114 kB raw, 21 kb gzippedNotFound.js
4 kB raw, 1.9 kB gzippedSearchResult.js
4.7 kB raw, 1.9 kB gzippedAppIndex.js
3 kB raw, 1.5 kB gzippedApparently, the chunks will be prefetched in Vue 3.0. I was not able to make them prefetch with the webpack magic comment
import(/* webpackPrefetch: true */ '')
for some reason. I am also unsure how to change the long file names. I triedoutput: { filename: '' }
in the webpack config and the magic comment/* webpackChunkName: "" */
, but no change.I got some good savings by dynamically loading the
moment
locale:cookbook-main.js
is almost unchanged and only one locale needs to be loadedI think we may be better off going after npm packages than our own code.Maybe we can lazy load the mardown editor, replace
ActionInput
, etc. I'm not sure whycalendar-js
andical
are needed, but both are pretty big. They seem to not be imported anywhere. I only see reference to them inpackage-lock.json
as a dependency ofnextcloud/vue
.Maybe we can also look into tree shaking.