Discussion:
[dart-misc] Why was Dart runtime written in C++?
Mike Lee
2017-02-19 09:57:57 UTC
Permalink
Hi

I am not an expert in this field at all, and was curious about the decision
tradeoffs made when choosing to implement the Dart runtime in C++. Was
there any other languages considered? Or was C++ simply chosen because of
previous experience with V8?

Specifically, I'm curious as to why not Go? Is a garbage collected language
even feasible to be used as a runtime? I'm very curious as to what the
advantages/disadvantages would be if Go was used as the runtime.

This may be a silly question but I'd appreciate any answers.

thanks!
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Joao Pedrosa
2017-02-19 23:52:07 UTC
Permalink
Hi,

C++ is one of the main blessed languages at Google. C++ is in fact used for
most of Google's core software. They describe it as a single codebase that
a lot of developers work on simultaneously. Google has many different
developer groups. One of them is for their core server-based platforms.
Another one was for the web centered around Chrome. Both of those were
mostly based on C++. When they are hiring new developers, C++ must be one
of their filters. With that preamble out of the way...

Dart was originally developed to be included within the Chrome browser,
which is mostly C++ already. Chrome is very demanding by itself, as it is
both multi-threaded and multi-process. The Dart VM they hoped would be
included alongside the JavaScript VM until some day when it could be the
only one. One of the difficulties of including a language VM within the
browser is that garbage collection and so on needs to be shared and
synchronized with the other features the browser provides like the HTML
DOM. The HTML DOM is very dynamic and code and data based on it needs to be
garbage collected kind of randomly. When all of that communication is
happening within a single process and within a single thread, things go
more smoothly than if they had to shove stuff through a bottleneck. Say,
when an HTML page is refreshed, if you can free it all up by dumping all of
its memory in one go it would be better than spending precious time waiting
for a central database to do its job. Part of the job of garbage collection
is exactly being able to free stuff up in milliseconds rather than going
thru a for loop to decide what needs to be dumped. Chrome was also one of
the early innovators of going multi-process rather than trying to do
everything from just multi-thread alone. These days, Firefox has finally
been able to go in that direction, as Firefox early on was heavily
dependent on multi-threading alone. On Unix, multiple processes has been a
feature for a long time. Windows went the multi-threading way. As Google
was a company that relied on Unix/Linux a lot, Google showed confidence in
multiple processes and the bet paid for itself on desktop version of
Chrome. Lately though with mobile, multiple processes seems to have become
an issue again, with Google Chrome apparently using a lot more battery than
the alternatives. And that brings us another feature of C++...

With C++, you may trade off safety for raw performance. Raw performance may
pay off in better graphics and also in doing more with less battery power.
Garbage collection is an extra abstraction layer that may cost in terms of
battery power. C++ is not known for garbage collection. Notice also that
garbage collection may require more memory to hold stuff that you don't
intend to collect right away. Then you collect more stuff in one go. I've
seen references that with garbage collection you may need 4 times as much
memory in order to be more efficient when allocating memory and collecting
garbage. With mobile and IoT and so on, memory is even more precious, as
third parties when developing hardware try to do more while using less
memory to save money on and sell their products more popularly.

Google is not in the business of recreating the browser in a new
experimental language. If anything, it looks as though Google is downsizing
the browser in order to better fit it on mobile and IoT etc.

Cheers,
Joao
Post by Mike Lee
Hi
I am not an expert in this field at all, and was curious about the
decision tradeoffs made when choosing to implement the Dart runtime in C++.
Was there any other languages considered? Or was C++ simply chosen because
of previous experience with V8?
Specifically, I'm curious as to why not Go? Is a garbage collected
language even feasible to be used as a runtime? I'm very curious as to what
the advantages/disadvantages would be if Go was used as the runtime.
This may be a silly question but I'd appreciate any answers.
thanks!
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Mike Lee
2017-02-19 23:58:13 UTC
Permalink
Thanks a lot Joao, answer was perfect!
Post by Joao Pedrosa
Hi,
C++ is one of the main blessed languages at Google. C++ is in fact used
for most of Google's core software. They describe it as a single codebase
that a lot of developers work on simultaneously. Google has many different
developer groups. One of them is for their core server-based platforms.
Another one was for the web centered around Chrome. Both of those were
mostly based on C++. When they are hiring new developers, C++ must be one
of their filters. With that preamble out of the way...
Dart was originally developed to be included within the Chrome browser,
which is mostly C++ already. Chrome is very demanding by itself, as it is
both multi-threaded and multi-process. The Dart VM they hoped would be
included alongside the JavaScript VM until some day when it could be the
only one. One of the difficulties of including a language VM within the
browser is that garbage collection and so on needs to be shared and
synchronized with the other features the browser provides like the HTML
DOM. The HTML DOM is very dynamic and code and data based on it needs to be
garbage collected kind of randomly. When all of that communication is
happening within a single process and within a single thread, things go
more smoothly than if they had to shove stuff through a bottleneck. Say,
when an HTML page is refreshed, if you can free it all up by dumping all of
its memory in one go it would be better than spending precious time waiting
for a central database to do its job. Part of the job of garbage collection
is exactly being able to free stuff up in milliseconds rather than going
thru a for loop to decide what needs to be dumped. Chrome was also one of
the early innovators of going multi-process rather than trying to do
everything from just multi-thread alone. These days, Firefox has finally
been able to go in that direction, as Firefox early on was heavily
dependent on multi-threading alone. On Unix, multiple processes has been a
feature for a long time. Windows went the multi-threading way. As Google
was a company that relied on Unix/Linux a lot, Google showed confidence in
multiple processes and the bet paid for itself on desktop version of
Chrome. Lately though with mobile, multiple processes seems to have become
an issue again, with Google Chrome apparently using a lot more battery than
the alternatives. And that brings us another feature of C++...
With C++, you may trade off safety for raw performance. Raw performance
may pay off in better graphics and also in doing more with less battery
power. Garbage collection is an extra abstraction layer that may cost in
terms of battery power. C++ is not known for garbage collection. Notice
also that garbage collection may require more memory to hold stuff that you
don't intend to collect right away. Then you collect more stuff in one go.
I've seen references that with garbage collection you may need 4 times as
much memory in order to be more efficient when allocating memory and
collecting garbage. With mobile and IoT and so on, memory is even more
precious, as third parties when developing hardware try to do more while
using less memory to save money on and sell their products more popularly.
Google is not in the business of recreating the browser in a new
experimental language. If anything, it looks as though Google is downsizing
the browser in order to better fit it on mobile and IoT etc.
Cheers,
Joao
Hi
I am not an expert in this field at all, and was curious about the
decision tradeoffs made when choosing to implement the Dart runtime in C++.
Was there any other languages considered? Or was C++ simply chosen because
of previous experience with V8?
Specifically, I'm curious as to why not Go? Is a garbage collected
language even feasible to be used as a runtime? I'm very curious as to what
the advantages/disadvantages would be if Go was used as the runtime.
This may be a silly question but I'd appreciate any answers.
thanks!
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Loading...