25

I spotted several articles about Wasm being faster then JS [1, 2]

I see the topic has been touched in this old (closed) issues [3, 4]

and this seemingly abandoned discussion on google groups [5];

the question is:

why flutter web doesn't use Wasm instead of dart2js ?

thank you for your time

(asked also on github)

5
  • I'm voting to close this question as off-topic because it should be asked on the flutter forums
    – ColinE
    Commented Sep 22, 2019 at 18:14
  • 8
    it's a technical question, I don't have the expertise to understand the reason of this choice, so I hope that someone would enlight me, I contacted flutter team as you see in the question, but for my understanding there's still an advantage to use wasm is some cases (example rendering) over dart2js... the fact that people more prepared than me disagree means that I'm missing a point... if you want me to rephrase the question: <what am I missing?> Commented Sep 22, 2019 at 21:43
  • I'm voting to close this question as off-topic because it's a call for opinions on the direction the framework should take, not a question about using the framework. Commented Nov 24, 2019 at 13:23
  • 1
    It is a technical question... of much interest... for "programmers"... and is a placeholder for people who already already had this issues to share their experiences and thoughts... so -> no close!!!
    – ZEE
    Commented Apr 27, 2021 at 18:35
  • docs.flutter.dev/platform-integration/web/wasm
    – Vencat
    Commented May 19, 2023 at 11:42

3 Answers 3

23

Vyacheslav Egorov (leading Dart AOT & JIT at Google) explains in this comment on Github that this is not clear at all that WASM is a better compilation target that JS.

It is without doubt that WASM is a better compilation target than JS for languages like C/C++ and Rust - languages where you manage your memory manually, where your calls are most often statically dispatched and primitive types are unboxed.

However if you start moving away from this kind of languages towards languages like Dart - which are full of dynamic behaviour, boxed primitive types and GC you will discover it becomes harder to claim with absolute certainty that WASM is a better compilation target than JS - because you would be forced to compile various runtime components (e.g. method dispatch implementation) into WASM - while in JS you get those things from underlying JS runtime and they are implemented natively and heavily optimised.

Another interesting thing to consider is that dart2js essentially benefits from two compilation steps - AOT compilation to JS and dynamic optimisation of this JS later by JS JIT. If AOT compiler fails to statically specialise some call site, there is still a chance that JS VM would manage to do that. You don't get such luxury with WASM.

There are a lot of other factors to consider (e.g. builtin libraries - do you want to implement your own array like structure in WASM with associated performance penalty, or do you just want to use heavily optimised native array?), etc, etc.

That said - I don't doubt that there are workloads and programs that would benefit from Dart targeting WASM. All I am saying is that expecting all Dart programs to magically get faster is incorrect.

1
  • the last lines of your quote: ""I don't doubt that there are workloads and programs that would benefit from Dart targeting WASM.""... like rendering? Commented Sep 22, 2019 at 21:57
10

During last Flutter Team AMA on reddit Flutter Team member Todd Volkert said:

WebAssembly is something we’re currently evaluating to see what opportunities exist for integrating it with Flutter. Nothing specific to report at this time.

Source

0
3

On July 27, 2021, Michael Thomsen (a Google product manager working on Dart and Flutter) published a blog post on the Dart blog titled, "Experimenting with Dart and Wasm". (Dart is the main programming language one uses when using Flutter to develop apps.)

They (Google) have been doing experiments to compile Dart to Wasm.

Bottom line: It's still early days, but it's definitely something they've been exploring.

Not the answer you're looking for? Browse other questions tagged or ask your own question.