Cordova JS-native Bridge Performance

ezAR provides a set of Cordova plugins for accessing native device functionality such as the camera and light from a JavaScript api. Recently I received a question about how long does it take the Cordova runtime to make a JS-native function call? Is it slow? Is it fast? What is it? From experience I knew it was quick enough for most of my use-cases. But I did'nt know the exact numbers. To answer this question I created a small app and Cordova plugin to measure the time it takes to make a native NOP function call from a Cordova app. See source code here

The app built with Cordova 6 SDK performs a 1000 calls to a NOP plugin's doNop() JavaScript function which in turn immediately calls the native doNop() implementation with no side-effects.  The native doNop() function returns immediately with a success status. Here's the results:

iPhone 6S (iOS 9.2.2)

Android Nexus 5 (v6.0.1)

The sub-millisecond median time is a non-issue in most use-cases for the benefit of accessing native resources. Also notice how the first use of the api is significantly slower than the median time. From this we can see how JS optimization kicks in with dramatic improvement. This info and a few other tests that I plan to run (e.g., structured data transfer) will be helpful in determining the design and implementation of future ezAR functionality.

Lastly, I used techniques and guidance from Measuring JavaScript Performance to compute these results. Specifically the performance.now() function was new to me.