Skip to content

Reducing bundle size and support tree-shaking #321

@mrxz

Description

@mrxz

The bundle size has grown significantly with the 2.0.0 release. Currently weighing in at about 5MiB, compared to 578.6kB for 0.1.10. It's now also 7x the size of Three.js itself, and gzipped even 11x. While most apps using Spark will end up loading a large amount of splat data, making the bundle size less relevant, there are still benefits to reducing the bundle size. For Spark to load any splat data, it has to be downloaded, parsed and initialized, making it part of the critical request chain. In other words, savings translate to app load time as well.

Bundlephobia: Three | Spark

The goal of this issue is to discuss and collect various ways to bring the bundle size down. Supporting tree-shaking would also help for users that use a bundler. If needed, it's even possible to look into multiple entry-points for the package (e.g. all-in-one bundle and a minimal one + sub-paths for optional features).

Some possible improvements:

  • Remove OldSparkRenderer and related classes #322. User can always stay on 2.0.0 or revert to 0.1.10 if needed.
  • Update compress-to-spz.js to use worker based loaders or deprecate the utility
  • Support tree-shaking (@sparkjsdev/spark@2.0.0 is difficult to tree-shake when importing only SplatMesh #319):
    • Ensure the entire bundle is side-effect free (or split side-effects into a separate file)
    • Make features like SplatSkinning, SplatEdits, SparkXr, etc... tree-shakable
  • Allow loading separate .wasm files (parallel loading, avoids Base64 inefficiencies)
  • Unify both .wasm blobs into one to avoid redundancy (instead of inlining twice, use postMessage to pass the Module to the worker)
  • Find ways to reduce the size of the .wasm blobs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions