Skip to content

Builds: Make three/tsl tree-shakeable. - #34533

Merged
sunag merged 1 commit into
mrdoob:devfrom
monken:tsl-tree-shakeable
Sep 17, 2026
Merged

sunag merged 1 commit into
mrdoob:devfrom
monken:tsl-tree-shakeable

Conversation

@monken

@monken monken commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Importing a single function from three/tsl currently keeps the whole TSL namespace 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 existing TSL namespace is kept for backwards compatibility.

Both core and TSL export log, so the core export keeps its name and the TSL function is exposed as logTSL. It's still exported as log from three/tsl.

I added a Rollup test that imports the renderer from the built three/webgpu file and color from three/tsl. For this example, the bundle sizes are:

Bundle size Before After
Minified 877,680 bytes 769,314 bytes
Gzipped 235,248 bytes 205,950 bytes

This contribution is funded by revanta.bio

@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
Core 389.51
102.17
389.51
102.17
+0 B
+0 B
WebGL 379.11
88.92
379.11
88.92
+0 B
+0 B
WebGPU 712.4
196.1
422.73
113.96
-289.67 kB
-82.14 kB
WebGPU Nodes 710.39
195.78
710.38
195.67
-6 B
-114 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 523.73
126.08
523.73
126.08
+0 B
+0 B
WebGPU 766.1
205.59
766.1
205.59
+0 B
+0 B
WebGPU Nodes 712.19
192.24
712.19
192.24
+0 B
+0 B

Comment thread src/Three.WebGPU.js Outdated
export { default as WGSLNodeBuilder } from './renderers/webgpu/nodes/WGSLNodeBuilder.js';
export { ClippingGroup } from './objects/ClippingGroup.js';
export * from './nodes/Nodes.js';
export * from './nodes/TSL.js';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this PR partially revert #29948?

Exporting every TSL function at top level has been removed on purpose.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a tradeoff between this and adding a three.tsl.js to the bundle. I pushed a revision that does just that. I know this has been discussed before but the reduced bundle size for application using only a handful of tsl function is worth it.

@Mugen87 Mugen87 Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll defer to @sunag here 😇 .

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me 👍

`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.tsl.js` is now built in the same Rollup pass as `three.webgpu.js`, so
the node code lives once in `three.tsl.js` and `three.webgpu.js` imports it,
the same way both already import `three.core.js`. `Three.TSL.js` re-exports
`nodes/TSL.js` directly and the public API of `three/webgpu` is unchanged.
@monken
monken force-pushed the tsl-tree-shakeable branch 2 times, most recently from 2e9aff6 to c5d35f8 Compare September 14, 2026 17:45
@mrdoob
mrdoob requested a review from sunag September 16, 2026 18:13
@mrdoob mrdoob added this to the r187 milestone Sep 16, 2026
@sunag
sunag merged commit c6c0296 into mrdoob:dev Sep 17, 2026
10 checks passed
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.

4 participants