-
-
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
Codesplit WebGL/WebGPU entrypoints #29404
Codesplit WebGL/WebGPU entrypoints #29404
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
test/rollup.treeshake.config.js
Outdated
input: 'test/treeshake/index.webgpu.nodes.js', | ||
input: 'test/treeshake/index.webgpu.js', |
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.
Undid this change, but three.webgpu.nodes.js
is unused, and duplicate with WebGPU (missing only the recent BundleGroup
export). CI still measures WebGL, WebGPU, WebGPU + Nodes. Maybe it can measure the common core instead?
This reverts commit 418db9b.
I think this looks like a good approach! Shared 'core' that the WebGL and WebGPU entrypoints can use, and that doesn't need to be exposed as a separate public entrypoint to users. (obsolete / resolved issue)Minor thing, but I'm seeing some duplication of build artifacts when running
|
This reverts commit 880e8bb.
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.
I will vote for Cody's approach here, as it keeps both the WebGL and WebGPU entrypoints minimal even when used from a CDN.
Alternatively we could skip the shared 'three.core.js' file and have 'three.webgpu.js' import from 'three.module.js'. That's fine for the bundler users, but CDN users would get a lot of extra JavaScript when trying to use WebGPU. So that would presumably be more of a temporary stopgap.
Tested:
- compared build sizes before/after in production builds
- compared build sizes before/after in dev builds
- no dual package hazard in production builds in an application w/ Vite
- no dual package hazard in development builds in an application w/ Vite
Should I just remove the build artifacts from this PR or regenerate them? |
Removing them is better 👍 . |
@mrdoob @sunag Fixing #29156 is crucial for the community so if there are no objections from your side let's merge this so we have a bit of room to The only workflow that is affected by this change is when devs copy builds around since there is |
I like the changes 👍 |
@mrdoob should definitely approve this change. The type of builds and the import structure is a fundamental aspect of the library and I'm not sure how he feels about this approach. I understand the PR is a great solution for our current promoted workflows (npm, CDN) but it moves away from the idea to have a renderer with its core classes in a single self-contained build file. Regarding #29644 I'm not sure it's a good user experience to have |
If you really need a compromise, we can bundle everything into the minified <script type="importmap">
{
"imports": {
"three": "../build/three.webgpu.min.js"
}
}
</script>
import * as THREE from 'three';
const renderer = THREE.WebGPURenderer(); // npm i three
import * as THREE from 'three/webgpu';
const renderer = THREE.WebGPURenderer(); |
This reverts commit ba0c5b4.
It seems the examples can't be properly debugged and inspected if the builds are minified. Ideally, they use an unminified bundle. That said, I'm personally fine with the initial approach you have implemented. I'm just curious to see how @mrdoob evaluates the PR and the need for self-contained bundles. |
Is there a reason we don't emit sourcemaps? That would have errors in all bundles point back to source code and allow tracing in Lighthouse. |
@CodyJasonBennett just checking you're aware that the sourcemaps are currently built with |
Gentle ping @mrdoob 😊. This PR has received approval from most collaborators, but before proceeding, we would really appreciate your input. The import structure and build types are critical to the library's architecture, and we'd like to understand your perspective on the approach: Self contained: // npm i three
import * as THREE from 'three/webgpu';
const renderer = THREE.WebGPURenderer(); Or not: import * as THREE from 'three';
import { WebGPURenderer } from 'three/webgpu' |
This update will still require people to update their build setups (or importmaps). The idea in #29156 (comment) would fully avoid the requirement for build setups to be updated, while providing optional ways to achieve the same goals as this new |
I elaborated in #29156 (comment), but this is a gross misdiagnosis. |
The The naming is becoming weird though. This would look better to me:
The What do you guys think of this?
three.core.js: Core |
@mrdoob For
... which could be implemented on top of |
Having used WebGPURenderer across all my projects for over a year, I fully agree with the concerns. Given the WebGPU API's ongoing instability, it seems premature to push this onto most Three.js developers, especially since many Three.js developers may not adopt WebGPURenderer for some time. Adding it now could undermine previous efforts to optimize bundle size through tree-shaking: (see #29827) A structure like this strikes a balanced approach:
This setup respects the longevity of There’s no real benefit in bundling both |
I think the naming suggestion is a good one, as the example Merging the two renderers into a single module could limit flexibility in the creation process. For example, in cases like I would suggest moving forward with the renaming and merging the PR as proposed, and addressing this additional issue later if needed. |
Absolutely. What has been suggested in #29404 (comment) sounds good to me as well. |
#29404 (comment) sounds good to me too 👍 |
Nice 🚀! Then I think we can merge this PR as it is? /cc @Mugen87 |
Yeah, let's start with this configuration. We can apply further updates with additional PRs if necessary. |
Hmm, how come the minified build is now -92.38 kB less? 🤔 |
I could imagine the script still measures the sizes based on a single build file and does not honor |
Ah, got it. I'll need to update that table again then... |
Fixed #29156
Description
Emits a build where
three/webgpu
re-exports from core to avoid user configuration or duplication. Each entrypoint will no longer bundle a unique copy of three.js but share a single copy.To prevent future issues with tree-shaking (#28670), I've code split the common core and code specific to a backend.