Skip to content

JS tree-shaking doesn't work well with class functions #2827

Open
@sffc

Description

@sffc

When building optimized WASM files, we rely on a good DCE algorithm for the target language. When JavaScript is the target, I've been able to tree-shake at least down to the class level; however, it seems that tree-shaking doesn't work lower than that. This means that all of the functions on ICU4XFixedDecimal, for example, are still present in the bundle and therefore linked into WASM.

Good discussion on this: rollup/rollup#349

It does seem that the Closure Compiler can support this, but when I tried it didn't seem to work for me. Probably spending more time on this could make it work.

A few paths forward:

  1. Continue investigations into a method that tree-shakes class functions using Closure Compiler.
  2. Investigate and/or implement alternatives, perhaps relying on TypeScript.
  3. Change Diplomat codegen so that each function is standalone, rather than in a class.

P.S. In terms of bundlers, I had the best luck with rollup for handling async dependencies. Using webpack resulted in a lot of unused classes being included because it doesn't seem to DCE along async dependencies.

Discuss with:

Optional:

  • Someone who knows a lot about JS/TS and build systems

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ffiArea: FFI, WebAssembly, TranspilationC-ffi-infraComponent: Diplomat, horizontal FFIquestionUnresolved questions; type unclear

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions