Compile dart in the browser
Asked Answered
B

1

6

In my application I generate big dart classes. Right now I compile them on the server, which takes CPU time. It would be much better to compile the Dart code within the browser. The code is then loaded via spawnURI.

Is it possible to invoke the dart2js compiler from within Dart code in a supported way as it is done in try.dartlang.org or do I need to copy the compiler into my project?

Barbarian answered 27/9, 2013 at 16:43 Comment(4)
It's... not very clear what you're trying to do. You compile Dart to JS only once, right? Besides try.dartlang.org does the compilation on the server. The dart2js compiler is not written in JavaScript, you can't run it on the browser.Biskra
We'd like to learn more about your use case. Care to ask at [email protected] ?Grillo
Juhana, but dart2js is written in dart, which you can compile with dart2js to javascript. Sounds recursive, but that is how it is ;)Barbarian
The use-case is the following. A user goes to beta.pshdl.org and starts coding something in PSHDL. He then wants to run a simulation of that PSHDL code. The PSHDL code is then compiled to Dart on the server side and loaded via spawnURI on the client-side. This works well when the client is a Dartium, which in most cases it is not. I thus need to compile the generated Dart code to js via dart2js. Unfortunately I don't have a google server farm to host all that, and so I want to move the dart2js to the client. I hope that helps. Some more explanation can be found on my blog.pshdl.orgBarbarian
G
4

Compiling Dart to JavaScript will be faster on the server, because you can run dart2js via Dart VM. try.dartlang.org is running in a special version of dart2js, which has not been merged into the main source code.

Grillo answered 27/9, 2013 at 22:25 Comment(3)
That is what I expected :(Barbarian
Can you tell us more about why you want to compile on the client? It's going to be slower. Thanks for the background.Grillo
Because each invocation of dart2js consumes at least 3.5s on the server. As I don't have a server farm, but really just a tiny virtual server handling multiple clients would totally block it. For example if 10 clients to decide to hit trigger the dart2js compilation at about the same time, the last one has to wait up to 35s. So even if the compilation on the client-side would take more than the 3.5s, it would probably be faster than on my well loaded server (which also has other stuff to do). Also each client will not just trigger the compilation once, but multiple times within a short time.Barbarian

© 2022 - 2024 — McMap. All rights reserved.