Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolanlawson/51494a70adb6ac026c20 to your computer and use it in GitHub Desktop.
Save nolanlawson/51494a70adb6ac026c20 to your computer and use it in GitHub Desktop.
SQLite Plugin not as fast as I thought
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<style>
.sidebyside {
display:inline-block;
max-width: 200px;
margin: 0 30px 20px 30px;
}
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote {
margin: 0;
padding: 0;
}
body {
font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", Arial, sans-serif;
font-size: 13px;
line-height: 18px;
color: #737373;
background-color: white;
margin: 10px 13px 10px 13px;
}
table {
margin: 10px 0 15px 0;
border-collapse: collapse;
}
td,th {
border: 1px solid #ddd;
padding: 3px 10px;
}
th {
padding: 5px 10px;
}
a {
color: #0069d6;
}
a:hover {
color: #0050a3;
text-decoration: none;
}
a img {
border: none;
}
p {
margin-bottom: 9px;
}
h1,
h2,
h3,
h4,
h5,
h6 {
color: #404040;
line-height: 36px;
}
h1 {
margin-bottom: 18px;
font-size: 30px;
}
h2 {
font-size: 24px;
}
h3 {
font-size: 18px;
}
h4 {
font-size: 16px;
}
h5 {
font-size: 14px;
}
h6 {
font-size: 13px;
}
hr {
margin: 0 0 19px;
border: 0;
border-bottom: 1px solid #ccc;
}
blockquote {
padding: 13px 13px 21px 15px;
margin-bottom: 18px;
font-family:georgia,serif;
font-style: italic;
}
blockquote:before {
content:"\201C";
font-size:40px;
margin-left:-10px;
font-family:georgia,serif;
color:#eee;
}
blockquote p {
font-size: 14px;
font-weight: 300;
line-height: 18px;
margin-bottom: 0;
font-style: italic;
}
code, pre {
font-family: Monaco, Andale Mono, Courier New, monospace;
}
code {
background-color: #fee9cc;
color: rgba(0, 0, 0, 0.75);
padding: 1px 3px;
font-size: 12px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
pre {
display: block;
padding: 14px;
margin: 0 0 18px;
line-height: 16px;
font-size: 11px;
border: 1px solid #d9d9d9;
white-space: pre-wrap;
word-wrap: break-word;
}
pre code {
background-color: #fff;
color:#737373;
font-size: 11px;
padding: 0;
}
sup {
font-size: 0.83em;
vertical-align: super;
line-height: 0;
}
* {
-webkit-print-color-adjust: exact;
}
@media screen and (min-width: 914px) {
body {
width: 854px;
margin:10px auto;
}
}
@media print {
body,code,pre code,h1,h2,h3,h4,h5,h6 {
color: black;
}
table, pre {
page-break-inside: avoid;
}
}
</style>
<title>SQLite Plugin not as fast as I thought</title>
</head>
<body>
<h1>SQLite Plugin not as fast as I thought</h1>
<p>I always assumed the SQLite Plugin was faster in Android than using the native <code>openDatabase</code>. It certainly keeps processing off the UI thread, which reduces jankiness in the app (e.g. a spinning GIF won't freeze), but it doesn't seem to actually increase raw speed. Turns out there's a cost to pay for switching between the JavaScript and Java VMs.</p>
<div class="sidebyside">
<p>Native <code>openDatabase</code>:</p>
<a href="screenshot1.png"><img src="screenshot1.png" height="400px"/></a>
</div>
<div class="sidebyside">
<p>SQLite plugin, latest as of July 2014 (<a href="https://github.com/brodysoft/Cordova-SQLitePlugin/commit/757d00e6cb1166c3055de97ee620d7bb6d398edd">this commit</a>):</p>
<a href="screenshot2.png"><img src="screenshot2.png" height="400px"/></a>
</div>
<div class="sidebyside">
<p>SQLite plugin, using a background thread instead of the app UI thread (<a href="https://github.com/nolanlawson/Cordova-SQLitePlugin/commit/d2a936d68e6b7205de8c9a459684541739e13783">this commit</a>):</p>
<a href="screenshot3.png"><img src="screenshot3.png" height="400px"/></a>
</div>
<p>So I guess the lesson learned is that the SQLite plugin is really only needed if:</p>
<ol>
<li>You have noticeable jank in your app because you're doing heavy database operations.</li>
<li>You need to bypass the storage limits on iOS, or if you're really using a lot of data, Android.</li>
</ol>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment