Alloy selective compilation, for an even faster Titanium development process
The typical development toolchain in a modern Titanium project involves many tools:
- Titanium itself;
- the Alloy framework;
- TiShadow, for faster development deployments/tests;
- one or several pre-processors (Coffeescript, Jade, STSS, ticons, etc.) and their Grunt bindings;
- Grunt and grunt-contrib-watch to wrap it all.
My colleague Claire already explained a lot in her conference “Titanium – Automating Workflow” during the TiConf Amsterdam, but recent projects have proved us that we can go one step further.
While TiShadow is a very good way of improving your production rate with Titanium and Alloy, it can be limited with large Alloy projects. We recently had the case with a huge codebase, where even using TiShadow wasn’t a sufficient improvement to make the developer’s life “easy”.
With our classical Titanium development environment, each and every file change launches the following steps:
- a file gets change (coffeescript, stss, etc.)
- grunt-coffescript compiles it from the
coffee
directory to theapp
folder - grunt-tishadow runs the
tishadow run
command
By default, in an Alloy project, the tishadow run
command runs a complete Alloy compilation, which means that every js, XML or tss file in the app
folder will be processed to create their equivalent in the Resources
folder. With a project large of 1000+ files, the Alloy compilation is slow (which means 5–15 seconds on a performant Macbook pro) and can be a pain for the developer, annihilating all the ease introduced by TiShadow.
TiShadow lately introduced the -s
switch, which allows to bypass the Alloy compilation, and therefore directly runs the code available in the Resources
directory. When developing an Alloy app, this won’t however match the requirements of the Titanium developer, who wants to be able to test the very last modifications made in the coffee or stss files.
We lately digged into Alloy’s compiler code and found it could be optimized to allow only process the compilation path of a single file. The pull request ALOY-620 – #625 introduces a new “file” option, which allows to tell the compile command which file was changed and which compilation path has to be worked out by the compiler.
When changing one single file in an Alloy project, there’s no more need for a complete Alloy rebuild: simply launch the compile
command with the file=
switch:
$ alloy compile --config platform=ios,file=app/controllers/index.js
Depending on the filetype (controller, stylesheet, view, theme, library, alloy.js, etc.), this will only re-generate the required files, not the whole bunch of Titanium Classic files it used to build. And the result is blazing fast:
$ time alloy compile --config platform=ios
...
[INFO] Alloy compiled in 9.64312s
$ time alloy compile --config platform=ios,file=app/controllers/index.js
...
[INFO] Alloy compiled in 0.40075s
Instead of waiting for almost 10 seconds, the Titanium developer will be able to observe the changes in a couple of seconds. Automating this flow with grunt-contrib-watch
and grunt-tishadow
isn’t an immediate task though. It requires several steps:
- watch for changes made in the
app
folder withgrunt-contrib-watch
. Listen for thechange
event and, for each file modified, change the configuration ofgrunt-alloy
to pass the name of the file to be changed ; - with
grunt-tishadow
, disable Alloy’s automatic compilation (skipAlloyCompile
set totrue
). A recently merged pull-request has made it possible and only listen changed onResources/
; - instead of developping in
app
orResources
, the developer now writes code in thesrc
folder. As a convenience, acopy
task copies everything (apart from ltss and coffee files) fromsrc
toapp
; - several instances of grunt-contrib-watch must be run simultaneously and, hence, are watching through grunt-concurrent.
I forked the Alloy Bootstrap project made by my colleague Vincent to wrap all the required tools together. If you have a look at it, pay attention to the Gruntfile’s watch
event manager. Most of the magic is made inside this listener, which drastically restricts the (pre-) compilation operations.
Developing for native targets can be painful and slow. TiShadow helped a lot in this sake, let’s make it a bit even faster!
Code Strong !
Commentaires et discussions
Speed up your Android Emulator!
If you develop applications for iOS and Android, you probably have used the iPhone Simulator and the Android Emulator. There is no real issue with the iPhone simulator, but Google one is very, very, very slow. It is so painful to debug with it that if you develop on Appcelerator’s…
Nos articles sur le même sujet
Ces clients ont profité de notre expertise
Ouibus a pour ambition de devenir la référence du transport en bus longue distance. Dans cette optique, les enjeux à venir de la compagnie sont nombreux (vente multi-produit, agrandissement du réseau, diminution du time-to-market, amélioration de l’expérience et de la satisfaction client) et ont des conséquences sur la structuration de la nouvelle…
À l’occasion de la 12e édition du concours Europan Europe, JoliCode a conçu la plateforme technique du concours. Ce site permet la présentation des différents sites pour lesquels il y a un appel à projets, et encadre le processus de recueil des projets soumis par des milliers d’architectes candidats. L’application gère également toute la partie post-concours…
Chugulu Games a souhaité que JoliCode l’accompagne, en tant qu’expert du framework Appcelerartor Titanium, dans le cadre du développement de l’application “Music Mania”. Nous avons profondément remanié la base de code existante, et aidé à garantir le bon fonctionnement de l’application sur iOS et Android, aussi bien sur smartphone que sur…