Perform more tree-shaking on worker code #118
Merged
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.
The bundle size of spark is 810 KB (for
spark.module.min.js). Inspecting the source map reveals that there is quite a lot of duplication in the bundle. The bundle contains the main source, as well as the worker source code. Since these two are effectively separate, any code referenced by both ends up twice in the final bundle. This includes thespark-internal-rssub-project with its WASM blob being included twice.On the worker side it turns out that it pulls in various parts of the user-facing classes (
SplatMesh,SplatEdit,SplatLoader), dyno classes/functions as well as various parts of Three.js.This PR configures Vite to perform more aggressive tree-shaking on the worker bundle. As a result many of the above mentioned chunks are no longer included in the worker source bundle (as they weren't actually needed in the first place). With this change the bundle size drops to ≈651 KB.
Ultimately it would be beneficial to make the separation between worker code and the main library code clearer. This can avoid situations where the two starts pulling in each-others code. Additionally the
@__PURE__and@__NO_SIDE_EFFECTS__annotations can be used to make the tree-shaking easier (and "safer").