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?

4
  • 1
    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.
    – JJJ
    Sep 27, 2013 at 17:02
  • We'd like to learn more about your use case. Care to ask at [email protected] ?
    – Seth Ladd
    Sep 27, 2013 at 22:25
  • Juhana, but dart2js is written in dart, which you can compile with dart2js to javascript. Sounds recursive, but that is how it is ;) Sep 28, 2013 at 8:06
  • 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.org Sep 28, 2013 at 8:09

1 Answer 1

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.

3
  • That is what I expected :( Sep 28, 2013 at 7:54
  • Can you tell us more about why you want to compile on the client? It's going to be slower. Thanks for the background.
    – Seth Ladd
    Sep 29, 2013 at 17:01
  • 1
    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. Sep 29, 2013 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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