Skip to content

Remaining tasks for allowing flutter tools to use dart compile wasm instead of invoking dart2wasm AOT snapshot & wasm-opt directly #54675

@mkustermann

Description

@mkustermann

Here's a list of remaining things we probably need to do before dart compile wasm can be used by flutter tools (right now it invokes the dart2wasm AOT snapshot burried in our SDK directly and wasm-opt with it's own set of binaryen flags):

  • Performance 16x slower (see below)
  • Support -D defines
  • Support --dart-sdk & --platform
  • Support --import-shared-memory & --shared-memory-max-pages
  • Support --depfile
  • Support passing through arbitrary args to dart2wasm (may also be used to do the above) - similar to (--extra-gen-snapshot-options in VM)

Performance
dart compile wasm is running the dart2wasm compiler in it's implementation (it doesn't use the dart2wasm AOT snapshot). Though the DartDev AppJIT training doesn't include dart2wasm compilation. That means the code will run slow.

It takes 8.5 seconds to run dart compile wasm vs 0.5 seconds by running the AOT snapshot (what flutter does):

% echo 'main() {}' > hello.dart

% time out/ReleaseX64/dart-sdk/bin/dart compile wasm --no-optimize hello.dart
*NOTE*: Compilation to WasmGC is experimental.
The support may change, or be removed, with no advance notice.

Generated wasm module 'hello.wasm', and JS init file 'hello.mjs'.
out/ReleaseX64/dart-sdk/bin/dart compile wasm --no-optimize hello.dart  12.87s user 1.81s system 173% cpu 8.471 total

% time out/ReleaseX64/dart-sdk/bin/dartaotruntime out/ReleaseX64/dart-sdk/bin/snapshots/dart2wasm_product.snapshot --platform=$PWD/out/ReleaseX64/dart-sdk/lib/_internal/dart2wasm_platform.dill --dart-sdk=$PWD/out/ReleaseX64/dart-sdk hello.dart hello.wasm
out/ReleaseX64/dart-sdk/bin/dartaotruntime    hello.dart hello.wasm  0.48s user 0.15s system 111% cpu 0.564 total

It's a little unclear to my why we wouldn't just run the dart2wasm AOT snapshot that we already bundle in the SDK for doing the compilation.

/cc @mit-mit

Metadata

Metadata

Assignees

Labels

area-dart2wasmIssues for the dart2wasm compiler.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions