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

[RFC] Bundle size optimization #1034

Closed
petermikitsh opened this issue Oct 3, 2018 · 4 comments · Fixed by #1130
Closed

[RFC] Bundle size optimization #1034

petermikitsh opened this issue Oct 3, 2018 · 4 comments · Fixed by #1130

Comments

@petermikitsh
Copy link
Contributor

petermikitsh commented Oct 3, 2018

As discussed in #1028, all @feathersjs namespaced modules (with the exception of @feathersjs/client) ship as ES modules, and it is the responsibility of users consuming these modules to compile them as necessary.

Surprisingly, @feathersjs/* packages are my 4th largest dependency.

screen shot 2018-10-03 at 11 34 30 am

Since we are already shipping ES modules, why not take advantage of language features such as import/export syntax, and then setting {sideEffects: false} in package.json files so you can get tree shaking?

One of the biggest files that is imported in the client is commons/lib/utils.js. This file is just a group of utility functions. It's the type of file that could potentially have a smaller footprint with tree-shaking.

Speaking to my particular use case, here is every file I import from the @feathersjs namespace sorted by filesize:

Filename Size
@feathersjs/authentication-client/lib/passport.js 10 KiB
@feathersjs/feathers/node_modules/@feathersjs/commons/lib/utils.js 8 KiB
@feathersjs/feathers/lib/hooks/index.js 7 KiB
@feathersjs/errors/lib/index.js 7 KiB
@feathersjs/feathers/node_modules/@feathersjs/commons/lib/hooks.js 6 KiB
@feathersjs/transport-commons/lib/client.js 5 KiB
@feathersjs/feathers/lib/application.js 4 KiB
@feathersjs/feathers/node_modules/@feathersjs/commons/lib/filter-query.js 3 KiB
@feathersjs/feathers/lib/events.js 3 KiB
@feathersjs/authentication-client/lib/index.js 1468 bytes
@feathersjs/authentication-client/lib/utils.js 1310 bytes
@feathersjs/authentication-client/lib/hooks/populate-entity.js 1174 bytes
@feathersjs/feathers/lib/hooks/base.js 1042 bytes
@feathersjs/socketio-client/lib/index.js 1019 bytes
@feathersjs/authentication-client/lib/hooks/populate-header.js 797 bytes
@feathersjs/feathers/lib/index.js 770 bytes
@feathersjs/authentication-client/lib/hooks/populate-access-token.js 381 bytes
@feathersjs/authentication-client/lib/hooks/index.js 318 bytes
@feathersjs/feathers/node_modules/@feathersjs/commons/lib/commons.js 202 bytes
@feathersjs/transport-commons/client.js 41 bytes
@feathersjs/feathers/lib/version.js 25 bytes
@daffl
Copy link
Member

daffl commented Oct 3, 2018

Feathers only uses language features that are natively supported by Node 6 or later. Unfortunately ES modules are not part of ES6 and not supported by Node yet. Size wise, the authentication client will likely be much smaller in the next version and the sorting utility could manually be put somewhere else. It is indeed not needed in Feathers core.

@petermikitsh petermikitsh changed the title [RFC] Consider using ES6 imports [RFC] Bundle size optimization Oct 3, 2018
@petermikitsh
Copy link
Contributor Author

The end goal is bundle size optimization, the imports were merely a suggestion of one possible strategy for achieving it. Optimization should be possible with the constraint of Node 6 (or later) functionality.

@petermikitsh
Copy link
Contributor Author

petermikitsh commented Oct 3, 2018

By the way -- you could still ship a transpiled build that supports Node v6 if you wanted to take advantage of newer JS features.

@daffl
Copy link
Member

daffl commented Oct 4, 2018

I think a lot can be gained here from the client in the next version of authentication, moving the sorting mechanism somewhere else and #932.

The reasons for dropping Babel compilation (it was used in pre Buzzard) have been outlined in #608 although some (like installing directly from GitHub) do not apply to the monorepo anymore.

I'm not opposed to adding a compilation step again but in that case, migrating the codebase to TypeScript (#565) - which is more well-defined than most non-standard ES features - would make more sense to me.

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

Successfully merging a pull request may close this issue.

2 participants