Builds: Make three/tsl tree-shakeable. - #34533
Open
monken wants to merge 1 commit into
Open
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
`three.tsl.js` re-exported every TSL function by reading it off the `TSL`
namespace object of `three/webgpu` (`export const abs = TSL.abs`). A single
import from `three/tsl` therefore kept the whole frozen namespace alive in
the consumer's bundle, and with it every node, lighting model, display pass
and GPGPU helper, whether or not the application used them.
`three/webgpu` now also re-exports the contents of `nodes/TSL.js`
individually, and `Three.TSL.js` becomes plain `export { ... } from
'three/webgpu'`, which bundlers can tree-shake. The `TSL` namespace export
is kept for backwards compatibility. `log` is exported by both
`Three.Core.js` and TSL, so the core export is re-exported explicitly and
the TSL one is exposed as `logTSL` for `three/tsl` to re-export as `log`.
A `test/treeshake/index.webgpu.tsl.js` entry that imports from the built
`three/webgpu` and `three/tsl` files measures the effect:
Before After
minified / gzip 877,680 / 235,248 769,314 / 205,950 (-108.4 kB / -29.3 kB)
monken
force-pushed
the
tsl-tree-shakeable
branch
from
September 10, 2026 16:37
b469a47 to
76f9e89
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Importing a single function from
three/tslcurrently keeps the wholeTSLnamespace in the bundle. Each export reads from that namespace (export const color = TSL.color), so unused nodes and helpers end up in the application's bundle as well.This PR exposes the TSL functions as named exports from both WebGPU entry points and uses plain re-exports in
Three.TSL.js. That allows bundlers to remove the unused exports. The existingTSLnamespace is kept for backwards compatibility.Both core and TSL export
log, so the core export keeps its name and the TSL function is exposed aslogTSL. It's still exported aslogfromthree/tsl.I added a Rollup test that imports the renderer from the built
three/webgpufile andcolorfromthree/tsl. For this example, the bundle sizes are:This contribution is funded by revanta.bio