storesafe / cordova-sqlite-storage

A Cordova/PhoneGap plugin to open and use sqlite databases on Android, iOS and Windows with HTML5/Web SQL API
Other
2.15k stars 715 forks source link

Thread warning when doing transactions #197

Open BastianBoerschig opened 9 years ago

BastianBoerschig commented 9 years ago

I am about to build a little eventcalender and when i recieve events from the server and want to write it in the database i get this warning: THREAD WARNING: exec() call to SQLitePlugin.backgroundExecuteSqlBatch blocked the main thread for 50ms. Plugin should use CordovaInterface.getThreadPool().

Blocked ms are mostly around 50 (40-60).

This is the relevant part of the code (without query not relevant stuff): capture

It works fine but causes this warning. Not always but about every 3rd to 5th run. At the moment there are about 3000 items in the database so it runs 60 times to get them all. It doesn't crash the app, anything works fine, but it's annoying.

brodycj commented 9 years ago

The plugin is already running the sql operations in the backgroud thread (one thread per database, as described in the readme). I don't know how many sql statements are in the db transaction. Looking at the code, I am suspecting the delay is due to some processing of the JSON arguments before putting them in the queue for processing in the background thread.

BastianBoerschig commented 9 years ago

There are 50 executeSql operations in each transaction. If i lower the number of statements per transaction the number of warnings also goes down. But up again if there are bigger data in the JSON object like binary data from images. So you're probably right, it's about the processing of the JSON. But since there is no noticeable slowdown or crashes, i think i might ignore the problem.

Thank you.

brodycj commented 9 years ago

Will be documented (when I get a chance).

adrianjarc commented 6 years ago

Also getting this thread warning but in my case there is an evident slowdown of app because I am using this to acces some scripts needed for further operations from db and because there can be 3-4 calls at the same time (that means 3-4 executeSql statements at the same time) some scripts get loaded too slow. Attached is one of the warnings. (At the moment I saved this log I got >50 of those warnings but that was my fault). At most I get around 10

log.txt