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

Add test-treeshake script #21437

Merged
merged 2 commits into from
Mar 10, 2021
Merged

Add test-treeshake script #21437

merged 2 commits into from
Mar 10, 2021

Conversation

marcofugaro
Copy link
Contributor

Related issue: #21292 (comment)

Description

Added a test-treeshake script (suggested by @mrdoob) so it's possible to see the tree-shaked size three.js has for people using bundlers (the Minified Size entry in the screenshot).

Screenshot 2021-03-10 at 10 41 40

The example code is the most basic working code, taken from the README.

It's importing three.js like if the user was importing it from the node_modules, so it imports build/three.module.js. This means that to test some changes you do locally in the src/ folder, you have to do:

npm run build && npm run test-treeshake

@mrdoob mrdoob added this to the r127 milestone Mar 10, 2021
@mrdoob mrdoob merged commit 4cfbf39 into mrdoob:dev Mar 10, 2021
@mrdoob
Copy link
Owner

mrdoob commented Mar 10, 2021

Thanks!

@marcofugaro marcofugaro mentioned this pull request Mar 10, 2021
43 tasks
@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 13, 2021

Seems the recent class migration further improved the bundle size 🎉.

@marcofugaro
Copy link
Contributor Author

marcofugaro commented Apr 13, 2021

Oh yes! Now if we remove some other deprecated methods we could get it down even more!

@mrdoob
Copy link
Owner

mrdoob commented Apr 13, 2021

Oh yes! Now if we remove some other deprecated methods we could get it down even more!

What other deprecated methods are those? 🤔

@marcofugaro
Copy link
Contributor Author

I actually did that test by removing Three.Legacy.js altogether 😅

These only are the blocking methods, if removed they shave off ~10kb

  • if removed, InstancedBufferGeometry.maxInstancedCount saves ~0.8kb
  • if removed, Curve.__arcLengthDivisions saves ~3.1kb
  • if removed, Raycaster.linePrecision saves ~1.42kb
  • if removed, InterleavedBuffer.dynamic saves ~2.17kb
  • if removed, MeshPhysicalMaterial.transparency saves ~3.5kb

The other ~30kb are taken up by the deprecated methods of the classes that can't be tree-shaken because they are always needed such as WebGLRenderer, WebGLShadowMap, Light, Matrix3, Matrix4, Vector2, Vector3, Object3d, Mesh, Material and so on. They can't bee tree-shaken because they act like class methods I guess, rollup example here.

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

Successfully merging this pull request may close these issues.

3 participants