What Fletch has in common with Dart VM?

270 views
Skip to first unread message

Anton Moiseev

unread,
May 7, 2015, 11:21:43 AM5/7/15
to mi...@dartlang.org
Hi guys. I was watching the Kasper's talk Dart for Mobile from the Dart Summit (one more time 😊), and came up with two questions on Fletch:
  1. Dart VM and Fletch are two runtimes for Dart. But is Fletch based on Dart VM or it's a separate implementation? I realize that as two runtimes for the same language being developed within one company they likely share some codebase, but is Dart VM a "dependency" for Fletch?
  2. In the presentation Kasper mentioned that Dart runs on iOS through interpretation. I wonder whether the fact that Dart VM is not bytecode-based helps implementing interpreted runtime and on-the-fly code changes, or it's completely irrelevant?
Disclaimer: I'm far from the VMs world, sorry if it sounds silly.

Thanks!

Bob Nystrom

unread,
May 7, 2015, 12:14:43 PM5/7/15
to General Dart Discussion
On Thu, May 7, 2015 at 8:21 AM, Anton Moiseev <an...@antonmoiseev.com> wrote:
  • Dart VM and Fletch are two runtimes for Dart. But is Fletch based on Dart VM or it's a separate implementation?

Totally separate implementation as far as I know.
 
  • I realize that as two runtimes for the same language being developed within one company they likely share some codebase, but is Dart VM a "dependency" for Fletch?

No, Fletch doesn't build on top of the VM.
 
  • In the presentation Kasper mentioned that Dart runs on iOS through interpretation. I wonder whether the fact that Dart VM is not bytecode-based helps implementing interpreted runtime and on-the-fly code changes, or it's completely irrelevant?

Whether or not the VM creates bytecode on the fly or native machine code (i.e. a JIT) doesn't really impact whether you can change code on the fly. Both styles are equally dynamic from that perspective.

The big difference is that if you a VM compiles to machine code on the fly, it needs the ability to tell the OS execute that generated code. At it's lowest level, a JIT does something roughly like:

1. Allocate a chunk of memory.
2. Write a bunch of x86/ARM/whatever machine code to it.
3. "Call" that chunk of memory as if it were a C function.

The details are a little different, but that's the basic idea. Your program jumps into a chunk of dynamic memory as if it contained compiled code—which it does, you just compiled it on the fly.

The ability to do step three is an OS feature. Some platforms allow it, some do not. iOS and most game consoles do not. You simply can't run a JIT on those platforms because the OS won't let you do step three. Instead, you have to do bytecode.

Cheers!

- bob


Anton Moiseev

unread,
May 7, 2015, 1:35:52 PM5/7/15
to mi...@dartlang.org
Ah... When Jony Ive starts talking about new Apple products (is that word allowed in this Google group?! :) ) your hand instinctively moves towards your wallet, when you guys start talking about Dart, the hands move towards GitHub repos :).

There is a lot of interest in Fletch lately, we'd love to hear any details the Dart team can share with us.

You simply can't run a JIT on those platforms because the OS won't let you do step three.
Is it mostly because of security or performance reasons? 

Jim Trainor

unread,
May 7, 2015, 1:53:08 PM5/7/15
to mi...@dartlang.org
I suggest you grab the code from github and build it and poke around.  It will pull in the rest of the dart source tree and build it along with the fletch code. I haven't dug too deeply yet. It built on OS X with no problems exactly per the instructions.


--
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

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Jim Trainor

unread,
May 7, 2015, 2:06:55 PM5/7/15
to mi...@dartlang.org
Part of the the answer to Apples executable page restrictions is here:


Only Apple apps have the ability to allocate writable/executable memory pages:



"Memory pages marked as both writable and executable can be used only by apps under tightly controlled conditions: The kernel checks for the presence of the Apple-only dynamic code-signing entitlement. Even then, only a single mmap call can be made to request an executable and writable page, which is given a randomized address. Safari uses this functionality for its JavaScript 
 JIT compiler. "

I believe also there are legal restrictions in the Apple AppStore agreement that impose further limitations on JIT.

None of that prevents interpreted code that is packaged with an app.  Lua, apparently, is commonly used in iOS apps as an example.





Joao Pedrosa

unread,
May 7, 2015, 2:07:06 PM5/7/15
to mi...@dartlang.org
Hi,

You simply can't run a JIT on those platforms because the OS won't let you do step three.
Is it mostly because of security or performance reasons? 
 
We can only speculate. But those are potentially some of the reasons they had in mind. A third reason could be that they wanted to maintain a grip on the kind of software that would run on their systems so that others could not create alternatives to their default offerings. Otherwise, if they restricted something and others came up with an alternative that did not maintain those restrictions, say a Chrome browser that still enabled the Flash plugin and so on, users would have an extra incentive to use the competing browser.

Apple have the argument that software that is too independent of the platform ends up not using all of the latest and greatest that the platform has to offer and that creates a dependency where Apple could come up with hardware features that the software would only much later have support for, if ever. They have an example of it in Java when they had support for it.

Cheers,
Joao

Jan Mostert

unread,
May 8, 2015, 4:21:30 AM5/8/15
to General Dart Discussion
I have a third question, is sky using fletch or does sky and fletch have different implementations for ios (and how are they different)
(my understanding is that fletch is just for ios and sky will support both ios and android, is this correct?)

--
Jan Vladimir Mostert
janvladimirmostert.com


On Thu, May 7, 2015 at 5:21 PM, Anton Moiseev <an...@antonmoiseev.com> wrote:
Hi guys. I was watching the Kasper's talk Dart for Mobile from the Dart Summit (one more time 😊), and came up with two questions on Fletch:
  1. Dart VM and Fletch are two runtimes for Dart. But is Fletch based on Dart VM or it's a separate implementation? I realize that as two runtimes for the same language being developed within one company they likely share some codebase, but is Dart VM a "dependency" for Fletch?
  2. In the presentation Kasper mentioned that Dart runs on iOS through interpretation. I wonder whether the fact that Dart VM is not bytecode-based helps implementing interpreted runtime and on-the-fly code changes, or it's completely irrelevant?
Disclaimer: I'm far from the VMs world, sorry if it sounds silly.

Thanks!

--

Joao Pedrosa

unread,
May 8, 2015, 5:02:39 AM5/8/15
to mi...@dartlang.org
Hi,

Based on what they said about Fletch during the conference videos that I watched, the primary purpose for Fletch is its interpretation of Dart code that is most useful on iOS. It seems to me that Fletch will work OK on Unix based systems, but initially it will not be developed for Windows. Right now anyone can test Fletch on Linux:

$ time ./out/ReleaseIA32/fletch_driver /home/dewd/t_/jungle/lion.dart 
Using config file: /home/dewd/dice/yofletch/fletch/.fletch
Total: 3750025000

real 0m0.289s
user 0m0.002s
sys 0m0.000s

$ time ./out/ReleaseIA32/fletch_driver /home/dewd/t_/jungle/lion.dart --out /home/dewd/t_/jungle/lion.snapshot
Using config file: /home/dewd/dice/yofletch/fletch/.fletch

real 0m0.255s
user 0m0.000s
sys 0m0.002s

$ time ./out/ReleaseIA32/fletch /home/dewd/t_/jungle/lion.snapshot
Total: 3750025000

real 0m0.022s
user 0m0.021s
sys 0m0.000s

$ time /home/dewd/apps/dart/dart-sdk/bin/dart /home/dewd/t_/jungle/lion.dart
Total: 3750025000

real 0m0.121s
user 0m0.126s
sys 0m0.024s

$ cat /home/dewd/t_/jungle/lion.dart

class A {

  cipo(n) {
    return n % 2 == 0 ? n ~/ 2 : n + 1;
  }

}

main() {

  var total = 0, o = new A();

  for (var i = 0; i < 100000; i++) {
    total += o.cipo(i);
  }

  print("Total: ${total}");

}

On mobile, getting the startup to be fast is a great goal to have. With Fletch they seem to have broken it into 2 parts. One that will be responsible for interpreting directly from source code and creating a snapshot of it when it's ready for deployment. And the other one that will run the snapshot when it's deployed. When Fletch runs the snapshot it is the fastest one at that. The Fletch runtime is highly optimized to running the snapshot.

Another feature of Fletch is that it can spawn tens of thousands of processes with minimal memory requirements. This is for its concurrency feature. Fletch seems to use just the minimum number of native threads that matches the number of CPUs that the machine has. In some ways this is similar to what people do with Go which also enjoys a lot of support for concurrency.

Fletch is so quick at loading up and at spawning subprocesses that it could be used in CGI, FastCGI, command line tools, and even as its own whole HTTP server, I guess. And those uses are beside its main goal of being used for mobile applications.

What happens in a web service? You may connect to a database, process some data, and return its output and drop the connection and its thread and/or process. Even in an interpreted language that is no problem.

I'm not sure how Fletch relates to Sky yet. I haven't yet given Sky a try or a lot of thought.

The problem of Fletch not supporting Windows may be an important one. But Windows sucks for forking processes, which is more of a Unix thing. Given that many developers are on Windows, it will not be easy to ignore it. I think that Microsoft prefers features that fit into a single process, like Async programming.

Cheers,
Joao

emoji_u1f60a.png

Bob Nystrom

unread,
May 8, 2015, 12:21:16 PM5/8/15
to General Dart Discussion, Kasper Lund, Ivan Posva

On Fri, May 8, 2015 at 1:20 AM, Jan Mostert <jan.m...@gmail.com> wrote:
I have a third question, is sky using fletch or does sky and fletch have different implementations for ios (and how are they different) 
(my understanding is that fletch is just for ios and sky will support both ios and android, is this correct?)

Good questions! Let me just add some of the people who can probably answer these better than I.

Cheers!

- bob


Seth Ladd

unread,
May 8, 2015, 12:38:27 PM5/8/15
to mi...@dartlang.org, rnys...@google.com, ipo...@google.com, kas...@google.com


On Friday, May 8, 2015 at 9:21:16 AM UTC-7, Bob wrote:

On Fri, May 8, 2015 at 1:20 AM, Jan Mostert <jan.m...@gmail.com> wrote:
I have a third question, is sky using fletch or does sky and fletch have different implementations for ios (and how are they different) 
(my understanding is that fletch is just for ios and sky will support both ios and android, is this correct?)

It's very early for both projects, and we don't want to speculate. Best we can say is: star the repos and follow along.

kc

unread,
May 12, 2015, 9:43:42 AM5/12/15
to mi...@dartlang.org, kas...@google.com, rnys...@google.com, ipo...@google.com
Sky rests on Mojo which has and idl and ipc. So there seems a lot of overlap between Fletch and Mojo (and gRPC).

It would be great if the Fletch concurrency story was designed to be integrated with Mojo/Sky/gRPC.
As well as driving 'native' ui's on iOS and Android.

And longer term a good concurrency story would play well on the server.

The idea of getting the biz logic off the UI/listening thread seems right and a natural partner to a runtime with concurrency baked in.

K.
Reply all
Reply to author
Forward
0 new messages