Skip to content

chore: add side effects for plugins - #1020

Open
julien-moreau wants to merge 1 commit into
masterfrom
fix/tree-shaking
Open

julien-moreau wants to merge 1 commit into
masterfrom
fix/tree-shaking

Conversation

@julien-moreau

Copy link
Copy Markdown
Contributor

No description provided.

@Soullnik

Soullnik commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for looking into this! I tested the PR against our app (Vite 6.4 / Rollup, @babylonjs/core 9.37 ES6 packages). I built tools from fix/tree-shaking, linked it in place of the npm package, and compared per-module sizes from the Rollup bundle.

tools build JS min JS gzip editor-tools modules in bundle
5.5.0 (npm) 8780 KB 2548 KB 38 / 67, 92 KB
master (d1248b3) 8924 KB 2586 KB 49, 339 KB
master + this PR 8924 KB 2585 KB 48, 339 KB

With Rollup, the sideEffects field changes almost nothing: only cinematic/events/apply-impulse.js drops out. Rollup already removes unused modules of the package on its own analysis. (It may help more with webpack.) Separately, master adds ~143 KB min / ~37 KB gzip over 5.5.0 even for a scene that doesn't use it, because of rendering/volumetric/*.

The real weight comes from code that is only reachable through loadScene. In our bundle, ~1.5 MB of unminified Babylon code (roughly 700 KB min) is pulled in only by editor-tools imports, almost all of it into the entry chunk:

  • @babylonjs/core/Particles (~520 KB): NodeParticleSystemSet, imported statically in decorators/apply.ts and loading/node-particle-system-set.ts
  • @babylonjs/core/PostProcesses + their shaders (~530 KB): SSR, SSAO2, TAA, motion blur, VLS, default pipeline, all imported statically by loading/rendering.ts through rendering/* (plus volumetric lighting on master)
  • @babylonjs/gui/2D (~240 KB): AdvancedDynamicTexture, imported statically in decorators/apply.ts
  • @babylonjs/core/Physics (~50 KB): PhysicsAggregate in loading/physics.ts

Since these are used inside functions reachable from loadScene, no bundler can drop them, with or without sideEffects. Our scene uses none of these features.

Would you consider the same approach you already use for the gui / navmesh preload plugins? Either:

  1. load these features lazily with import() only when the scene data contains them (rendering configs, particle sets, GUI decorators, physics aggregates), or
  2. make them opt-in plugins registered through a side-effect import (babylonjs-editor-tools/loading/plugins/post-processes, etc.). Your sideEffects list would then keep them only when the app imports them.

Either way, a scene that doesn't use them would stop paying for them. Happy to test a branch.

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.

2 participants