You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
node_sqlite3 queries blocking the renderer process #2542
I'm using Electron 0.30.4 on Mac OS X 10.10.3. The project I'm working on uses node-sqlite3 in the renderer process and makes queries for data to display.
The SQLite3 module uses uv_queue_work(uv_default_loop()... to run queries on the libuv thread pool. If I understand correctly, this means that the heavy lifting of performing the query shouldn't block the renderer process. However, this doesn't seem to be the case.
Using the content-tracing module, I generated profiles of our Electron app just before a particularly expensive query is executed. You can see in the profile that the renderer process is blocked in MessageLoop::RunTask for a very long time. This causes the entire UI to "stick" - things don't render, animate, etc. during that time. The Chromium Developer Tools profiler shows no activity in that window, and nothing is really visible in the content-tracing output.
I'm fairly sure that this long call to MessageLoop::RunTask corresponds to the execution of an expensive query in SQLite. To test, I kept the data and application exactly the same and added/removed the indexes from the table being queried.
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(':memory:');
db.serialize(function() {
db.run("CREATE TABLE test (id INT, test TEXT)");
var stmt = db.prepare("INSERT INTO test (id, test) VALUES (?, ?)");
for (var i = 0; i < 100000; i++) {
stmt.run(Math.floor(Math.random() * 100000), "Ipsum " + i);
}
stmt.finalize();
console.log('done');
// db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
// console.log(row.id + ": " + row.info);
// });
});
db.close();
Activity
zcbenz commentedon Aug 28, 2015
Can you give an example that can show this problem? I tested with this:
The result is only 2~3ms.
zcbenz commentedon Sep 17, 2015
Closing until more information is provided.
mikey0000 commentedon Jul 6, 2017
Try doing this one