Interview with Lars Bak about Dart
theregister.co.uk
theregister.co.uk
"Bak now reckons Dart runs 30 per cent faster on Google's V8 than JavaScript under the Richards operating system kernel simulation benchmark and under the DeltaBlue benchmark – two standards used at Google."
What's perhaps most important for Dart at this stage isn't how much faster its VM is than Javascript; what matters is how its generated Javascript performs relative to hand-written Javascript in browsers without a Dart VM.
These two benchmarks are publicly tracked at http://www.dartlang.org/performance/
Dart VM is used to provide smooth developer experience and can operate standalone on the server side (there is dart:io library) which makes its raw performance quite important, from my point of view.
> Dart VM is used to provide smooth developer experience and
> can operate standalone on the server side (there is dart:io
> library) which makes its raw performance quite important,
> from my point of view.
The server side is a bit irrelevant here; nobody's pretending that Dart's ever going to get traction on the server side if it doesn't first have a strong stake on the client side. And if I'm pitching to my team that we should use Dart for our web applications, I need to know that my performance won't be dreadful on the majority of installed browsers in the world.One more question: is there a reason you only run two of the Octane benchmarks, rather than the entire suite? More data points would make for a more convincing argument.
> is there a reason you only run two of the Octane benchmarks
As the FAQ states at the very bottom of the page: Porting benchmarks correctly takes time.
As more benchmarks become ready, we will publish more charts.
Some Octane benchmarks are quite hard to port either because they are very big (PDF.js), generated by some sort of compiler (e.g. Mandreel and EarleyBoyer) or exercise things that might not necessarily have any direct translation to Dart (RayTrace is using class emulation code take from prototype.js).Vyacheslav, I bet everybody and their dog would be most grateful if somebody pointed out those side effects that prevent JS from being snapshotted.
JavaScript programs lack declarative structure.
There is no way to declare a class with a fixed set of fields and methods. Instead JavaScript program creates functions and sets up their prototype property as it executes.
No way to declare a module. Instead developers create and immediately invoke a nameless closure.
One can say that the structure (things that people view as "classes" and "modules") behind JavaScript program is the side-effect of this very program executing. There is no clear border between "structure initialization" and execution.
So the first issue arises: to snapshot something you need to guarantee that deserialized snapshot will result in the very same "structure" that would arise from executing this code from scratch. This imposes certain restrictions on the way the JavaScript code should be written and how its initialization should be laid out. If for example application starts interacting with DOM early in its "initialization" phase then this is hard to snapshot correctly.
But an opposite is true as well: other programs (scripts) executing in the same environment might affect the structure that JavaScript program weavers as it runs.
Consider for example the following code:
function Point() {
}
Point.prototype.distance = function () { /* ... */ };
It might look like we could snapshot it and then unconditionally deserialize it into a Point function with a distance property on an object in its prototype property. But this is not true. If our deserialization does not happen in the clean environment (e.g. we are not the very first thing that is running on the page) then somebody can install "distance" property with a setter on the Object.prototype thus altering execution of our initialization entirely. This means that deserialization code must account for that.So we have two points to care about:
(a) JS code must be written in a special way to benefit from snapshotting, serializer must bail out from the attempt to snapshot "unsound" initialization code;
(b) deserializer must ensure correctness when unpacking.
If you ensure that both hold then you can actually snapshot your JS code and benefit from it.
V8 in fact does this internally: some JavaScript builtins are written in JavaScript and "snapshotted" to speed up their initialization. But V8 snapshots are cutting corners:
- Point (a) is ensured manually. "Unsound" initialization code in builtins just leads to mysterious bugs. There is no verification, toolchain does not reject any code.
- Point (b) is guaranteed because deserializer is applied when the world is empty and untouched by the user code.
This is not something you can use for an arbitrary JS code AS IS... and filling up the gaps requires hard efforts on both VM and application side.
Dart does not have any problems like that because the structure behind the program is static. So snapshotting is simple to implement and it works for any application, not requiring any "restructuring" from the app developer.
Hopefully the VM will be easy to target from other languages.
- syntax to be a step backwards. Useless tokens everywhere, distinction between expressions and statements, no macros or some other extension mechanism. Docstrings-in-comments. Silly operators like &&. Increment operators, even with post/pre distinction! The switch, with yet another form of fall-through. "new" keyword for creating objects. I thought we'd all learned that C/Java syntax is stupid.
- the distinction between production and development mode to be dangerous (no asserts in production). Behaviour differs enough to be confusing
- anything can be thrown. Why even bother with an exception type then?
- I see no value in specifying types if they aren't actually checked all the time. Generics are equally optional. We'll see if this experiment proves me wrong, but I doubt it.
- constructors are complex and confusing. For some reason they don't get inherited
- static methods. They aren't class methods, so why even bother? The docs even recommend not using them
- peculiar boolean context. For some reason, everything is falsy except for true
- no ADTs or at least non-nullable types
On the other hand, it gets many other things right (module system, less crazy semantics than JavaScript, properties, operator methods, libraries are saner, etc.). It's just sad that it could've actually been a nice language.
To reply to some of your points:
The syntax is designed to look like Java. It's there for Java programmers, not to be the best syntax ever. (new is important, however, because you can also create objects with const.) Yeah, it's not Python.
Production and development mode are a common optimization in other languages. Remember: type annotations in Dart cannot, by design, change the behavior of the application. So in production mode, that part of the language spec is enforced. Static analysis tools, etc., are free to do whatever they want, however. I'd rather catch type errors at code review time rather than at runtime in production anyway.
The constructors make sense to me. They work like Java, and there is better syntax for initializing fields (which is all I ever do in constructors anyway).
Ultimately, it's Java in client-side form. Compare it to GWT, not Python or Haskell.
I'd have hoped for a more interesting language for such an interestingly pedigreed VM.
I doubt that would help you. The Dart VM is tailored to the Dart language (which in turn was designed with the thought of compiling to JS in mind), it would be suboptimal for anything else. Exceptions happen, but they are very rare.
But yes, for languages like Scala etc., they run quite well on the JVM, well enough for sure.
That is, I can't see this being too compelling for the majority use case of browsers. Without that, I can't see not having Dart support being an issue for competing browsers.
http://javascriptjabber.com/008-jsj-v8-and-dart-with-lars-ba...
Interesting listen.
I know this was unintentional, but I agree, for the most part side effects are bugs.