3 ms·
As the author of a program that's both scripting-centric and performance-centric [1], I've looked at this question in detail. I needed the fastest possible embe
by pierrec 11y ago
As the author of a program that's both scripting-centric and performance-centric [1], I've looked at this question in detail. I needed the fastest possible embeddable scripting language and interpreter. When I say "fastest possible", I mean for signal processing, so my application is different from the article at hand, which is about shell scripting rather than application-embedded scripting.
C / TCC was great, but TCC doesn't attach much importance to final speed optimization. I had a working prototype but ended up scrubbing it for that reason.
C++ / Clang / LLVM has the best end speed and optimizer, and as the article points out, the language is looking better and better. However, as a library it's pretty massive, difficult to embed, and compilation would probably be too slow for a REPL/JIT type of situation, though I haven't tested this with a working prototype.
Lua / LuaJIT is what the project is currently using. Since this is HN, I guess I don't need to say anything about how fast it is. However, my application (and many others, I suspect) would get a large performance improvement (I estimate 3x) if the compiler was capable of working with float32 operations and of optimizing them into vectorized SIMD instructions. This is why I'm currently looking at the next possibility:
Javascript. With the recent introduction of different float widths and SIMD in major Javascript JIT compilers, this option is starting to be the fastest possible (in my case). I'm planning to make a prototype to verify this, and I'm not too keen on joining the JS bandwagon, but if LuaJIT development continues to be basically halted, I'll have to get with the times. What I need is at the bottom of an epic TODO list for LuaJIT [2] that hasn't really moved for years. I don't know who's in a position to make a move on those LuaJIT open sponsorships, I really wish they would do it! I for one don't really feel up to the task.
[1]: http://osar.fr/protoplug http://osar.fr/protoplug
[2]: http://wiki.luajit.org/Open-Sponsorships http://wiki.luajit.org/Open-Sponsorships
- seabee 11y agoSince you're already using Lua, maybe you'll have an easier time switching to Terra. It supports SIMD, and you only need to deal with embedding LLVM. http://terralang.org http://terralang.org
- pierrec 11y agoInteresting, I looked at Terra before but hadn't noticed the SIMD. The fact that it only supports doubles (instead of float32 which Javascript now supports and vectorizes) makes this a bit less awesome though. SIMD becomes more powerful when you can use smaller data types, which is why JS engines are proud of the float32 + SIMD combination that they now have. And ideally, you shouldn't need to always specify vector operations, the compiler should optimize your loops (for example) into SIMD instructions. But as far as I know, very few compilers are capable of doing this now. I think some C/C++ and Java compilers are among the only ones, though the example given here suggests that Spidermonkey should also do it to some extent: https://bugzilla.mozilla.org/show_bug.cgi?id=894105#c2 https://bugzilla.mozilla.org/show_bug.cgi?id=894105#c2
- oscargrouch 11y agoThe Dart VM is really good/optimized for SIMD from the beggining, and its jitted, maybe another option for you. If you are using Luajit you can game the typesystem, by using the FFI interface, making math much more performant by using the FFI C interface. I think i would go through that route first