-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
WebGLUniforms: Assign compareFunction
lazily to retain tree-shaking.
#28670
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
src/renderers/webgl/WebGLUniforms.js
Outdated
@@ -569,6 +568,13 @@ function setValueT1( gl, v, textures ) { | |||
|
|||
} | |||
|
|||
if ( this.type === gl.SAMPLER_2D_SHADOW && emptyShadowTexture === null ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it also fix the tree shaking issue if we do the following?
let emptyTexture2D;
if ( this.type === gl.SAMPLER_2D_SHADOW ) {
emptyShadowTexture.compareFunction = LessEqualCompare;
emptyTexture2D = emptyShadowTexture;
} else {
emptyTexture2D = emptyTexture;
}
I suspect tree-shaking breaks since the code accesses compareFunction
right away. If we just move this bit to setValueT1()
, we don't need an additional if
check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, anything were we don't do a mutation in the top-level scope.
Add comment
compareFunction
lazily to retain tree-shaking.
So this PR allows |
Yes, effectively. I'm seeing unreasonable effectiveness in Vite (importing from |
How come this PR made the tree shaking number bigger and not smaller? 🤔 |
That doesn't measure tree-shaking actually, but the output of one configuration of one tool. The untreeshaken size increases since we're adding a branch to the source. It's like saying something affected device performance, but only accounting for one device/driver at one version. |
Oh, what should we do to measure tree shaking then...? |
Either a matrix of tools and configuration, or be okay with measuring the lowest common denominator. That might mean testing tree-shaking in three as a whole rather than the practical case of rendering a scene with a WebGLRenderer, where this has no effect. I test a bunch here for instance. https://github.com/CodyJasonBennett/treeshaking |
Related issue: #24199
Description
Did a quick test for tree-shaking in core (importing a constant), and found the usual expected culprits (mutations from setting static properties in
Texture
,Euler
,Object3D
, and devtools), but also a seemingly low hanging fruit in WebGL source. Everything else is both annoying to fix and expected to be present in user-land code for rendering.