Submitted Final Version 2
Submitted Final Version 2
Gilles Callebaut∗ , Michiel Willocx† , Jan Vossaert† , Vincent Naessens† , Lieven De Strycker∗
Leuven ∗ KU
MSEC, imec-DistriNet
Ghent Technology Campus, 9000 Ghent, Belgium
{michiel.willocx, jan.vossaert, vincent.naessens}@cs.kuleuven.be
Abstract—The mobile world is fragmented by a variety of mobile device features (i.e., sensors and other platform APIs) remains
platforms, e.g., Android, iOS and Windows Phone. While native an obstacle. In many cases, the developer is forced to use a
applications can fully exploit the features of a particular mobile limited set of the native APIs, or to use a work-around –which
platform, limited or no code can be shared between the different often involves native code– to achieve the desired functionality.
implementations. Cross-Platform Tools (CPTs) allow developers This paper specifically tackles the use case of data storage APIs
to target multiple platforms using a single codebase. These
in Cordova. This paper extends our previous work [1] with an
tools provide general interfaces on top of the native Application
Programming Interfaces (APIs). Apart from the performance elaboration of the inner workings of the Cordova framework and
impact, this additional layer may also result in the suboptimal use new experiments concerning the employed bridge mechanisms.
of native APIs. More specifically, this paper focuses on Apache Cordova is one of the most used CPTs [2][3]. It is a Web-
Cordova; the most used CPT. Via a data storage case study, the to-native wrapper, allowing the developer to bundle Web apps
impact of the abstraction layer is analyzed. Both the performance into standalone applications.
overhead and API coverage are discussed. Based on the analysis,
an extension to the cross-platform storage API is proposed and Contribution. The contribution of this paper is fourfold.
implemented. In addition, the Cordova framework, including the First, the Cordova framework including the Cordova Bridge
employed bridge techniques, is studied and elaborated. is discussed. Second, four types of data storage strategies
Keywords–Cross-Platform Tools; data storage; performance are distinguished in the setting of mobile applications (i.e.,
analysis; API coverage; Apache Cordova/Phonegap. variables, databases, files and sensitive data). The support for
each strategy using both native and Cordova development is
analysed and compared. Third, based on this analysis a new
I. I NTRODUCTION Cordova plugin that extends the Cordova Storage API coverage
An increasing number of service providers are making their is designed and developed. This plugin tackles a shortcoming
services available via the smartphone. Mobile applications are in the currently available Cordova APIs. Finally, the security
used to attract new users and support existing users more and performance of the different native and Cordova storage
efficiently. Service providers want to reach as many users as mechanisms is evaluated for both the Android and iOS platform.
possible with their mobile services. However, making services The remainder of this paper is structured as follows.
available on all mobile platforms is very costly due to the frag- Section II points to related work. Section III gives an overview
mentation of the mobile market. Developing native applications of CPTs. Section IV discusses the inner workings of Cordova
for each platform drastically increases the development costs. applications, followed by Section V where an overview of
While native applications can fully exploit the features of a data storage strategies and their API coverage in Cordova and
particular mobile platform, limited or no code can be shared native applications is given. The design and implementation of
between the different implementations. Each platform requires NativeStorage, a new Cordova storage plugin, is presented in
dedicated tools and different programming languages (e.g., Section VI. Section VII presents a security and performance
Objective-C, C# and Java). Also, maintenance (e.g., updates or evaluation of the Cordova and native storage mechanisms with
bug fixes) can be very costly. Hence, application developers a strong focus on the performance evaluation. The final section
are confronted with huge challenges. A promising alternative presents the conclusions and points to future work.
are mobile Cross-Platform Tools. A significant part of the code
base is shared between the implementations for the different II. R ELATED W ORK
platforms. Further, many Cross-Platform Tools such as Cordova Many studies compare CPTs based on a quantitative
use client-side Web programming languages to implement assessment. For instance, Rösler et al. [4] and Dalmasso
the application logic, supporting programmers with a Web et al. [5] evaluate the behavioral performance of cross-platform
background. applications using parameters such as start-up time and memory
Although several Cross-Platform Tools became more mature consumption. Willocx et al. [6] extend this research and
during the last few years, some skepticism towards CPTs include more CPTs and criteria (e.g., CPU usage and battery
remains. For many developers, the limited access to native usage) in the comparison. Further, Ciman and Gaggi [7] focus
specifically on the energy consumption related to accessing Examples of such mobile JavaScript frameworks are: JQuery
sensors in cross-platform mobile applications. These studies are Mobile [13], Ionic [14] and Sencha Ext JS [15].
conducted using an implementation of the same application in Two strategies can be applied to distribute the applications
a set of cross-platform tools and with the native development to end-users. First, an application (i.e., Web app) can be
tools. This methodology provides useful insights in the overall hosted on a Web server. This flexible approach allows the user
performance overhead of using CPTs. Other research focuses on to access the application in a mobile browser in a platform-
evaluating the performance of specific functional components. agnostic manner. Hence, a large market can be easily reached
For instance, Zhuang et al. [8] evaluate the performance of the and the time-to-market can be short. However, the application
Cordova SQlite plugin for data storage. The work presented in is constrained to the resources available in the browser. For
this paper generalizes this work by providing an overview and instance, the JavaScript API of the browser (e.g., access to
performance analysis of the different data storage mechanisms sensors such as accelerometer and GPS) is more limited than
available in Cordova, and comparing the performance with using native approaches. Furthermore, accessing the application
native components. is more cumbersome than starting an application installed on
Several other studies focus on the evaluation of the device.
cross-platform tools based on qualitative criteria. For in- A second strategy is to pack the Web app into a standalone
stance, Heitkötter et al. [9] use criteria such as development application by using a Web-to-native wrapper. The resulting
environment, maintainability, speed/cost of development and application is often called a hybrid app due to the fact that it has
user-perceived application performance. The user-perceived both native as well as web characteristics. The packaging results
performance is analyzed further in [10], based on user ratings in an application that can be submitted to the app stores of the
and comments on cross-platform apps in the Google Play Store. different platforms. The Web app does not longer reside in the
The API coverage (e.g., geolocation and storage) of cross- browser, but in a chromeless (without the window decoration
platform tools is discussed in [11]. It is complementary with of a regular web browser) WebView. The application consists
the work presented in this paper, which specifically focuses of the WebView wrapper and the applications HTML, CSS
on the API coverage, performance and security related to data and JavaScript files. The Web-to-native wrapper also features
storage. a JavaScript bridge that allows access to a broader range of
platform APIs compared to the browser-exposed functionality.
III. C ROSS -P LATFORM T OOLS A typical structure of a hybrid application is illustrated in
Cross-platform tools can be classified in five categories Figure 1. The most popular Web-to-native wrapper is Apache
based on their employed strategy [12]: JavaScript frameworks, Cordova, formerly PhoneGap.
Web-to-native wrappers, runtimes, source code translators and
app factories. The latter provides a drag-and-drop interface to B. Source-Code Translators and Runtimes
allow the creation of simple applications without programming Another CPT strategy is translating source code to code
knowledge. This paper focuses on the web-to-native wrapper which can be understood by the underlaying platform such
Cordova. However, an overview of relevant CPT strategies is as a runtime. Runtimes shield applications from underlying
given to illustrate the differences, similarities and rationales. platform differences through compatibility layers. The applica-
We can further classify cross-platform tool strategies in: (I) tion source code can be either compiled or interpreted by the
web-based CPTs and (II) source-code translators and runtimes. runtime during execution.
Also, the source code can be translated to the platform’s
A. Web-Based Cross-Platform Tool Strategies native language or to executable byte code via a Source-Code
JavaScript frameworks as well as Web-to-native wrappers Translator. Popular source code translators are Xamarin [16]
make use of Web technologies for the development of mobile and Qt [17]. In most cases, a combination of a source-code
applications. A major advantage of these tools is that they translator and a runtime is employed where a compilation step
enable Web developers to participate in mobile application translates the source code to a binary or intermediary language
development. Due to the availability of web browser capabilities that runs on the runtime. In a minority of tools, the source
in mobile operating systems this strategy is widely adopted. code will run straight on the runtime (e.g., Titanium [18]) or
The user interface of such an application is developed with will be translated to native source code without a runtime (e.g.,
HTML and CSS, and the functionality is implemented using NeoMAD [19]). For each platform, the resulting source code is
JavaScript. compiled using the development tools provided by the platform
To adapt to the specific interfaces and navigation patterns developer.
of mobile applications new mobile Javascript frameworks have
been developed. These mobile interfaces are optimized for IV. C ORDOVA F RAMEWORK
smaller screen sizes compared to regular websites and, for A typical Cordova application consists of three important
instance, provide support for the touch UI of mobile devices. components: the application source, the WebView and plugins,
Some frameworks also try to mimic the UI of native applications as depicted in Figure 1. The Cordova framework allows these
by providing native skins. Thereby tailoring the UI of the components to exchange information. A crucial component
application to the look and feel of the platform on which is the Cordova bridge which provides a way to connect the
it is running. These skins, however, do not provide a fully client-side native code with the JavaScript source.
native experience. Most JavaScript frameworks also support
traditional architectural design patterns such as Modelviewcon- A. Cordova Application Structure
troller (MVC) and Modelviewviewmodel (MVVM) to facilitate The application code is loaded in a chromeless WebView.
the development of well-structured and maintainable code. By default, Cordova applications use the WebView bundled
of the selected bridging mechanism, the data requires several
conversion steps before and after crossing the bridge.
B. Cordova Bridges
It is crucial to understand the inner workings of this bridge
to be able to correctly evaluate the performance of the Cordova
storage APIs. Here we consider the used bridge techniques on
the Android and iOS platform.
Default in Android, Cordova uses the
addJavaScriptInterface method for reaching
the native side. This method injects a supplied object into the
WebView. Afterwards an interface to the client-side Android
code is accessible in JavaScript running in the WebView.
This results in a bridge which can be invoked in JavaScript.
Cordova invokes the evaluateJavascript method to
execute JavaScript code in client-side Android.
Figure 1. Structure of a Cordova application. Light grey arrows represent The following bridge techniques are used in Android to
JavaScript calls, darker grey arrows represent native calls. The Cordova exchange data and commands:
framework is illustrated by the grey area.
• JavaScript to Native Android:
◦ JS Object (default). Methods of a Java object
are directly accessed in Javascript via the
with the operating system. An alternative is to include the addJavaScriptInterface as described
Crosswalk WebView [20]. The Crosswalk WebView provides above.
uniform behaviour and interfaces between different (versions ◦ Prompt. The data is communicated through
of) operating systems. Hence, developers do not need to take the prompt functionality of the WebView. This
into account the differences in behaviour/APIs between the is used pre-JellyBean (i.e., Android 4.1), where
WebViews contained in the different (versions of) operating addJavascriptInterface is disabled.
systems. Despite the efforts of the Crosswalk project, the • Native Android to Javascript:
maintenance and further developments have halted. The Android
platform WebView has moved to an application so it can be ◦ Evaluation Bridge (default). Through
updated separately to the Android platform. As a consequence, evaluateJavascript native Android
the crosswalk WebView will not yield a better performance code can execute JavaScript directly. This
on devices were the WebView is kept up-to-date. Therefore, bridge was recently added and is now the
we do not consider the impact of the crosswalk project on the default bridge.
performance of data storage strategies in this paper. ◦ Polling. The JavaScript side can be accessed
by periodically polling for messages using the
Cordova developers have two options for accessing device Javascript to Native Bridge.
resources: the HTML5 APIs provided by the WebView and ◦ Event interception. The Javascript code inter-
plugins. Despite the continuously growing HTML5 function- cepts events (i.e., Load URL and Online event)
ality [21] and the introduction of Progressive Web Apps [22], and extracts the message from that event.
the JavaScript APIs provided by the WebView are not –yet–
sufficient for the majority of applications. They do not provide In iOS similar bridge techniques can be used. The
full access to the diverse resources of the mobile device, such javascript-to-native bridge is realized via URL loading in-
as sensors (e.g., accelerometer, gyroscope) and functionality terposition. On the JavaScript side a URL is loaded in
provided by other applications installed on the device (e.g., an iframe or via XMLHttpRequest (XHR). This loading is
contacts, maps, Facebook login). Plugins allow JavaScript code intercepted by the native side. The JavaScript side com-
to access native APIs by using a JavaScript bridge between municates via the native side by encoding messages inside
the Web code and the underlying operating system. Commonly these URLs. The native side can access the JavaScript side
used functionality such as GPS are provided by Cordova as by executing JavaScript code via the WebView’s method
core plugins. Additional functionality is provided by over 1000 StringByEvaluatingJavaScriptFromString.
third-party plugins, which are freely available in the Cordova
plugin store [23]. Plugins consist of both JavaScript code and V. DATA S TORAGE I N C ORDOVA
native code (i.e., Java for Android, Objective-C and recently This work focuses on data storage mechanisms in Cor-
Swift for iOS). The JavaScript code provides the interface to the dova applications. Four types of data storage strategies are
developer. The native source code implements the functionality distinguished: files, databases, persistent variables and sensitive
of the plugin and is compiled when building the application. The data. Databases are used to store multiple objects of the same
Cordova framework provides the JavaScript bridge that enables structure. Besides data storage, databases also provide methods
communication between JavaScript and native components. For to conveniently search and manipulate records. File storage can
each platform, Cordova supports several bridging mechanisms. be used to store a diverse set of information such as audio, video
At runtime, Cordova selects a bridging mechanism. When an and binary data. Persistent variables are stored as key-value
error occurs, it switches to another mechanism. Independently pairs. It is often used to store settings and preferences. Sensitive
data (e.g., passwords, keys, certificates) are typically handled 1 // coarse grained API
separately from other types of data. Mobile operating systems 2 NativeStorage.setItem("reference_to_value",<value>,
<success-callback>, <error-callback>);
provide dedicated mechanisms that increase the security of 3 NativeStorage.getItem("reference_to_value",<success-
sensitive data storage. callback>, <error-callback>);
The remainder of this section discusses the storage APIs 4 NativeStorage.remove("reference_to_value",<success-
callback>, <error-callback>);
available in Cordova and native Android/iOS. A summary of 5 NativeStorage.clear(<success-callback>, <error-
the results is shown in Table I. callback>);
Boolean Boolean
Disk A. Performance
Web App Plugin Developers want to be aware of the potential performance
impact of using a CPT for mobile app development [12].
(b) Fine-grained API This section evaluates the performance of the different storage
mechanisms for Cordova applications and compares the results
Figure 2. NativeStorage API
with the native alternatives. Each storage strategy is tested by
deploying a simple native and Cordova test application that
intensively uses the selected storage strategy on an Android
C. Evaluation of NativeStorage and iOS device. For Android the Nexus 6 running Android 6
was used, for iOS the IPhone 6 running iOS 9 was used. The
The plugin is evaluated based on the previously listed test application communicates the test results via timing logs
requirements. that are captured via Xcode for iOS and Android Studio for
Persistent storage is provided via the native storage mech- Android. The experiments were run sufficient times to ensure
anisms. The documentation of the used native mechanisms the measurements adequately reflect the performance of the
does not state a limitation on the storage capacity. Hence, as tested storage mechanisms.
opposed to LocalStorage, the storage capacity is only limited 1) Databases
by the available memory on the device, satisfying R1 . a) Test Application The database test application exe-
The native part of the plugin is developed for both Android cutes 300 basic CRUD operations (i.e., 100 x create, 100 x
and iOS. These mobile operating systems have a combined read, 50 x delete and 50 x read) of objects containing two
market share of 99% [30]. The used native storage mechanisms string variables. The performance is determined by means of
were introduced in iOS 2.0 and Android 1.0. The plugin, hence, measuring the total duration of all the transactions. This test has
provides support for virtually all versions of these platforms been executed using the SQLite (native and Cordova), WebSQL
used in practice, satisfying R3 . (Cordova) and IndexedDB (Cordova) mechanisms.
The plugin uses NSUserdefaults and SharedPreferences b) Results and Comparison The results are presented in
to store the data in app-private locations, ensuring that the Table II. The mechanism for retrieving values by means of an
variables can not be accessed from outside the application. index clearly results in a better performance compared to the
This satisfies R4 . SQL-based mechanisms. This analysis shows that IndexedDB
The APIs are implemented using an asynchronous non- provides an efficient way of storing and retrieving small
blocking strategy, facilitating the development of responsive objects. WebSQL –provided by the WebView– acts as a
applications (conform R5 ). wrapper around SQLite. This is illustrated by the performance
overhead associated with this mechanism. The deprecation of
Web developers are familiar with duck typing used in the specification/development stop could also have contributed
languages such as JavaScript. These types of languages often to the performance penalty. The SQLite plugin suffers from
have APIs that don’t distinguish between data types. The coarse- a performance overhead caused by the interposition of the
grained API provides such a storage mechanism. This API is Cordova framework/bridge and has consequently a noticeable
shown in Listing 6. Not all Cordova developers, however, have
a Web background. Therefore, a fine-grained API (Listing 5) 1 The statistics of the NativeStorage plugin can be found at https://npm-
is provided for developers who are more comfortable with a stat.com/charts.html?package=cordova-plugin-nativestorage.
performance overhead. The performance overhead introduced 4,000
by the Cordova bridge is discussed in more detail in the Native Write
0
1
2
3
4
5
6
7
8
9
10
IndexedDB 6.94 12.47*
WebSQL 153 128 Filesize [MB]
SQLite Plugin 133 116
Figure 4. Duration of file operations in iOS
2) Files
a) Test Application The test application distinguishes and write using the Cordova platform on Android. Tables V
between read and write operations. Each operation is tested and VI provide the results for iOS. Before data can be sent
using different file sizes, ranging from small files (∼ 1 kB) to over the Cordova bridge, it needs to be converted to a string.
larger files (∼ 10 MB). The performance of small files provides This can create significant overhead when large binary files
a baseline for file access. The performance of the read and such as images need to be manipulated. Before they are sent
write operations itself can be determined via the results of the over the bridge, the binary data is converted to a Base64 string.
large files. This test has been conducted ten times for each On Android, this is illustrated in the Processing file component
file size. The read and write operations consist of different of Table IV. Sending the data over the bridge also comprises
steps on Android and iOS. Both the duration of the individual a significant part of the overhead (i.e., Sending over bridge,
steps and the entire operation (i.e., read/write) is measured via from Table III). For small files, the overhead originates for the
timestamps. The application’s memory footprint is measured via most part from resolving the platform-independent URL to a
Instruments tool (Activity Monitor) in Xcode and via Memory local path and retrieving meta-data. Similar observations can
Monitor in Android Studio. be made based on the iOS results.
b) Results and Comparison The results of the timing
analysis on Android and iOS are presented in Figures 3 TABLE III. E XECUTION TIME OF COMPONENTS ASSOCIATED WITH A READ
and 4, respectively. In both Android and iOS a significant OPERATION IN C ORDOVA A NDROID (F ILE P LUGIN ). T HE PROCEDURE
”S ENDING OVER BRIDGE ” CONSISTS OF ENCODING , SENDING AND
performance difference between the native and the Cordova DECODING MESSAGES FROM THE JAVA S CRIPT SIDE TO THE NATIVE SIDE .
mechanism can be observed. R/W operations via the file plugin
take longer compared to the native mechanisms. On top of Component Duration [1 MB] Duration [20 MB]
a performance overhead, Cordova also comes with a higher (ms) (% total) (ms) (% total)
memory consumption, especially in iOS (Figure 5).
Resolve to local URL 58 46 59 7.56
Native reading 20 16 366 47
4,000 Native Write Sending over bridge 28 22 339 43
Operation duration [ms]
Native Read
Cordova Write Total 126 780
3,000 Cordova Read
2,000
Memory. In iOS, applications manipulating large files will
require large amounts of memory. This is illustrated in Figure 5.
1,000 As shown, reading and writing a 10 MB file results in 400 MB
of allocated memory. Reading and writing files larger than
0 10 MB can result in unstable behavior on iOS due to the large
memory requirements. A solution for developers is to split
0
10
15
20
0
1
2
3
4
5
6
7
8
9
10
Sending over bridge 59.93 19.39 587.19 20.71