I've been researching the idea of using embedded languages in mobile applications as a way of reusing business logic across platforms. I haven't found a lot of information about how much an embedded language will bloat an app's size, so I decided to see for myself. So far, I've written simple "Hello, world" apps for both Lua and Squirrel. Lua is a simple language that has been heavily used in video games for years. Squirrel is a newer language that was inspired by Lua, but uses a more C-like syntax.
These tests are not very scientific, and only demonstrate the bare minimum task of including the language support as a native shared library, and some JNI code to run a script to generate a "Hello, world" message which is returned to the activity.
Lua and Squirrel app delivery overhead (.apk size differences) | |||
language | start size | final size | overhead |
Lua | 12817 (13K) | 60089 (59K) | 47272 (46K) |
Squirrel | 13530 (13K) | 118520 (116K) | 104990 (103K) |
Squirrel (sans compiler) | 13530 (13K) | 99598 (97K) | 86068 (84K) |
I'm frankly blown away by the compact size of these language implementations, especially after getting the impression that including Javascript (via Rhino) would cost many hundreds of kilobytes. That wouldn't be a problem for many apps, but for certain small apps, Rhino could end up being much larger than the app itself. In the case of Lua, which is implemented in a mere 20 C source files, you not only get the Lua virtual machine in 46K, but the compiler to boot! Developers can and do use Lua on other platforms such as iOS, and the Lua code has even been compiled to Javascript via emscripten (an LLVM Javascript backend), which adds the potential of reusing code in HTML5 apps.
I haven't played around with writing code in these languages, though, so I'm curious to hear about people's real-world experiences.
posted at 2012-02-04 21:29:46 US/Mountain
by David Simmons
tags: squirrel android lua
permalink
comments