Mobile Transit FTW

July 2, 2015

Transit was released by Cognitect last summer. At the time, my impression was that there is actually “meat” behind this library in that it

  1. addresses some inherent problems related to the anemic type system of JSON, and
  2. is fast, using native JSON parsers

Apart from that, I had no real need to look into it, until now. Here's my success story; I hope it helps.




Recently I've been working on Replete, a bootstrapped ClojureScript REPL iOS app, and one problem was that launch could be slow (up to 40 seconds or so) on older iOS devices, owing primarily to the length of time spent reading edn files containing cached compiler metadata.

David Nolen suggested evaluating Transit as a faster alternative. Before doing that, I did the easy test of simply inlining the compiler metadata directly into the Replete source. (An aside: This was trivial, given the data is readable Clojure value literals. Copy-n-paste, baby!)

The inlined variant improved things on an iPad 3, reducing the 30 seconds spent setting up the compiler metadata to only 4 seconds. While this felt like a hack, it could effectively solve the launch performance problem.

Then I updated Replete to use Transit instead. First, I checked that JavaScriptCore does indeed have the needed JSON.parse functionality. (This is part of what makes the Transit approach fast—it is a bit of built-in native functionality.) Then I updated Replete's build script to convert the edn files to Transit files, and I replaced Replete's launch logic that reads edn with the analog for loading Transit. (The Transit APIs are wonderfully simple—I invested no time in “learning” them, and just went with a few lines from READMEs.)

In the end, for this use case, Transit ended up being read in just as fast as the approach using inlined ClojureScript data literals, thus being a perfectly suitable solution to the problem. On top of that, Replete no longer needs to bundle the original edn, and instead can bundle Transit, which is about 14% smaller for my use case.

Cool stuff. I'm now convinced of Transit, both in its speed and ease of use!

Tags: iOS ClojureScript Replete Bootstrap