Hi,
For the past few days I have started playing with Fletch more seriously. Fletch has a FFI feature that allows for invoking some arbitrary system functions to extend it with. It seems that FFI has been an important way for languages to get extensions. I first heard of FFI in Ruby, but it seems that the LuaJIT has gone one up on almost everyone else by dynamically compiling C function signatures and such, so that the LuaJIT may have one of the most advanced FFI supports out there. It does cause people to be locked to it I guess. I've been browsing some of the LuaJIT mailing list posts, and in one of them they were even suggesting that LuaJIT allows for using C structs for a faster than the "metatable" way to code, it seems. LuaJIT is just phenomenal, except that the language is not like Dart.
Fletch's FFI seems to be custom-made. It doesn't seem to use any external FFI library. The API set seems to be smaller than others, but it works so I have used it to create extensions that I have posted to my experimental Fletch project here:
For my Arpoador project I have added some more ways to work with Files and Directories. Added a FileBrowser class to search directories. I'm also experimenting with the important Fletch socket support. Next I want to support running command-line tools from Fletch and capture the output. If you want to start a HTTP server with Arpoador you can use just code like this:
import '../../lib/arpoador.dart';
import '../../lib/io/io.dart';
import '../../lib/lang.dart';
handleSocket(socket) {
Momentum.handle(socket, (req, res) {
res.writeHead(200, {"Content-Type": "text/html"});
res.writeBuffer(IO.readWholeBuffer("sample_file.html"));
});
}
main() {
Momentum.listen(handler: handleSocket);
}
I tried to keep an API similar to what people are used to in Node.js and similar systems. By writing directly from buffers rather than first loading the file content into strings I got a performance boost for serving static files, so I kept it. Here's the kind of performance that it gets me:
[snip]
Concurrency Level: 100
Time taken for tests: 0.800 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 3590000 bytes
HTML transferred: 2980000 bytes
Requests per second: 12497.84 [#/sec] (mean)
Time per request: 8.001 [ms] (mean)
Time per request: 0.080 [ms] (mean, across all concurrent requests)
Transfer rate: 4381.57 [Kbytes/sec] received
[snip]
Fletch's concurrency allows it to use all the CPUs, which is absolutely great compared to what we normally get with scripting languages. I did notice that performance starts to fall whenever I've added some more features. I added a Request parser (only header is being parsed, no Post body yet.)
Fletch is pretty quick though. But it has safety nets like bounds checking in FFI that can hurt performance a little bit when we are extending it. My feeling is that Fletch is at least about as fast as normal Lua since I ran a couple of benchmarks to compare them. But on pure number crunching it's no surprise that Fletch would lose to JIT VMs.
Also Fletch has a lot of support for Dart but is still missing things like loading functions with named parameters... But this week after I upgraded the Fletch version, I noticed a small performance improved in one of the "ab" tests I did. That is, Fletch is being actively worked on and I hope that they can succeed. Having a second great VM for Dart code would be awesome. And now that even Microsoft seems to be thinking about restricting JIT in their mobile systems, Fletch could be useful on Windows phones some day. :-)
For now Fletch does not support Windows yet, though. You need Linux or MacOSX to give it a try.
Cheers,
Joao