Skip to content

Electronjs application freeze problem on database reading #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fkomaralp opened this issue Jun 21, 2018 · 7 comments
Open

Electronjs application freeze problem on database reading #241

fkomaralp opened this issue Jun 21, 2018 · 7 comments

Comments

@fkomaralp
Copy link

fkomaralp commented Jun 21, 2018

Hi, I have a question. I'm working on electronjs app and I need a db on this application. My database read code is

    var filebuffer = fs.readFileSync('assets/db/sql.db');

    var db = new SQL.Database(filebuffer);
    var contents = db.exec("SELECT * FROM employees");
    console.log(contents)

While reading database my electronjs app freeze a little bit time. After read database application is working normal. How can I solve this problem? On line SQL.Database(filebuffer)

@jon-moreira
Copy link

I have the same problem!
While read and write! the electron app freeze while writing or reading data from database!

@fkomaralp do you found any solution or alternative to that?

@linonetwo
Copy link

In my electron app, initSqlJs() just won't resolve, it's pending forever!

@lovasoa
Copy link
Member

lovasoa commented May 14, 2019

@linonetwo Your problem does not seem to be the same as the one described above.

If you are making an electron application, then I would suggest using a native SQLite instead of this project. It will load faster and avoid freezes.

For instance, you can use https://www.npmjs.com/package/sqlite3

@lovasoa
Copy link
Member

lovasoa commented May 14, 2019

@fkomaralp can you reproduce the problem with the latest WASM sql.js ?

@linonetwo
Copy link

It's difficult to get native modules work, even sqlite3.

I thought WASM will work in electron v5, but seems it's not.

@lovasoa
Copy link
Member

lovasoa commented May 14, 2019

Both native module and wasm can work in electron. You should prefer native modules for performance. Electron has a documentation page dedicated to them.

In any case, please report issues to sql.js only when you have a clean and reproducible example.

@strogonoff
Copy link

strogonoff commented Oct 17, 2020

For the record, Electron’s renderer GUI will stutter while you are doing something blocking in the main thread, like reading data. This is how Electron works, it’s not a fault of SQL.js.

The solution for that that I prefer is using Node worker threads, and performing all expensive computations in there. In the main thread you’d start the worker, and during runtime you’d pass messages to it and get the results.

Note: the Node workers I am talking about run in Electron main thread. This is not the same as Web workers, which run in renderer. The worker bundled with SQL.js is a Web worker. However, I think SQL.js exposes basic APIs that you can wrap in Node workers yourself. I am considering this personally, as I’m choosing a fast storage to use for caching data used by my Electron app. With a library like https://threads.js.org (which I already use) it is possible to give your workers nice async APIs, and not have to deal with message passing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants