Nitro JavaScript Engine in iOS PhoneGap Apps
One advantage to building PhoneGap applications is that you can test your application on a physical device before registering with a developer program. Just host all of your source files on a web server and and point the device’s web browser at the server.
$100 per year to enroll in a developer program isn’t the end of the world, but I’d rather keep it until I know I have something to release!
Of course, with this testing method your application will not have access to device functionality exposed through the PhoneGap API, but it is still a good way to rapidly prototype your application’s user interface.
On iOS, there is another caveat to this testing method. Mobile Safari executes JavaScript faster than PhoneGap’s UIWebView.
Mobile Safari’s JavaScript engine is called JavaScriptCore, and is also referred to as Nitro. Nitro in mobile Safari just-in-time (JIT) compiles JavaScript into native machine code, rather than interpreting it. According to some benchmarks, JIT compilation in Nitro can improve the speed of JavaScript execution by 200% to 300%.
As of iOS 6, JIT compilation is only enabled in mobile Safari. JavaScript executing in a UIWebView will not be JIT compiled.
While this may sound like a crippling issue for iOS PhoneGap applications, it usually isn’t much of a problem. JIT compilation only speeds up JavaScript execution, it has no effect on layout and rendering, including hardware accelerated rendering.
If your application performs intensive computations in JavaScript, you can use the old setTimeout trick, or possibly web workers, as a way to keep the UI thread responsive. Even with JIT compilation, using these techniques to keep the UI thread responsive is considered best practice.
You should test how (the lack of) JIT compilation affects your application’s performance. The most obvious way to do this is to deploy your application to a physical iOS device. There is another way that will let you delay enrolling in the iOS developer program a little longer. Install Google Chrome for iOS. Google Chrome for iOS uses the same UIWebView component that your PhoneGap application will use, and therefore is similarly stunted when it comes to JIT compilation.