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

WebGLUniforms: Assign compareFunction lazily to retain tree-shaking. #28670

Merged
merged 3 commits into from
Jun 17, 2024

Conversation

CodyJasonBennett
Copy link
Contributor

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.

Copy link

github-actions bot commented Jun 16, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
679.4 kB (168.3 kB) 679.4 kB (168.3 kB) +3 B

🌳 Bundle size after tree-shaking

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

Filesize dev Filesize PR Diff
457.4 kB (110.4 kB) 457.4 kB (110.4 kB) +10 B

@@ -569,6 +568,13 @@ function setValueT1( gl, v, textures ) {

}

if ( this.type === gl.SAMPLER_2D_SHADOW && emptyShadowTexture === null ) {
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@Mugen87 Mugen87 added this to the r166 milestone Jun 17, 2024
@Mugen87 Mugen87 changed the title WebGLUniforms: lazily create shadow texture for tree-shaking WebGLUniforms: Assign compareFunction lazily to retain tree-shaking. Jun 17, 2024
@Mugen87 Mugen87 merged commit 8a7848a into mrdoob:dev Jun 17, 2024
12 checks passed
@CodyJasonBennett CodyJasonBennett deleted the webgl-treeshaking branch June 17, 2024 20:27
@mrdoob
Copy link
Owner

mrdoob commented Jun 18, 2024

So this PR allows DepthTexture to be tree-shaked?

@CodyJasonBennett
Copy link
Contributor Author

Yes, effectively. I'm seeing unreasonable effectiveness in Vite (importing from three) with the changes which tree-shakes down to REVISION, __THREE_DEVTOOLS__ and __THREE__. Before, it included Object3D etc. which is more expected. Trying to understand this.

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.

None yet

4 participants