Skip to content

Conversation

@mrxz
Copy link
Collaborator

@mrxz mrxz commented Jul 14, 2025

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 the spark-internal-rs sub-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").

@dmarcos
Copy link
Contributor

dmarcos commented Jul 14, 2025

Thanks so much!

@dmarcos dmarcos merged commit 141e2f3 into sparkjsdev:main Jul 14, 2025
2 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.

2 participants