3 ms·
>> Don't you want strong typing for better performance? > That's what I thought, too. The VM designers say that in practice, type guarantees really don't help
by azakai 15y ago
>> Don't you want strong typing for better performance?
> That's what I thought, too. The VM designers say that in practice, type guarantees really don't help them nearly as much as you might think, because type checks are not a major drain on performance.
If this is the case, what is supposed to make Dart faster than JavaScript? It sounds like they will end up around the same speed.
- roestava 15y agoDart is built with c++ and the algorithms won't always be super-optimized. I'm a little skeptical regarding performance as well, but the idea is that Dart makes code a little more static than JavaScript and that can help with calling methods in tight loops for example. If anything, it will allow Dart to close the gap to more static languages in that regard. More optimizations will only be possible with the longterm success of the platform. And for that will have both JavaScript and Dart.
- jashkenas 15y agoThe main difference that may allow Dart to run faster than JavaScript isn't type checks, but objects having static shape at runtime. In JavaScript, I can write this: var dog = new Animal(); dog.name = "Fido"; ... adding a new field to the "dog" object, even though other objects of the same class may have no such field. Objects that share common sets of fields are the famous "hidden classes" that V8 is able to optimize. You can't write the above example in Dart. Dart doesn't have to work as hard as V8 to discover and cache hidden classes, because the shape of an object is statically fixed to be the same as its class.
- azakai 15y agoYes, but how much of a slowdown is it to manage hidden classes? Furthermore, in the most performance sensitive code, you might not even have classes at all, just raw calculations (for example on typed arrays), which Dart will be no faster than JS at.
- DasIch 15y agoIf you know the shape you can reduce attribute access to an array lookup, if you don't attribute access requires a hash table lookup. That is a problem for performance and memory consumption.
- azakai 15y agoSure, but again, (1) JS engines can and do infer the shape at runtime using hidden classes, and they also get array lookups that way (and not hash table lookups), and (2) I suspect these lookups are not even on the critical path of typical performance-intensive code, but that's speculation of course.