0

I experienced a huge performance difference between android 2.3.4 and 4.0.3 on HTC Sensation.

Some additional information:

  • ormlite version 4.42
  • to getting dao I use DaoManager and a dao singleton.
  • using batch task to insert
  • I'm trying createorupdate 30 objects (only creating takes the same time)
  • These are single objects (without relations), but have long string fields.

Time logs:

ICS (4.0.3)

10-16 09:17:06.206: 1 getting dao
10-16 09:17:06.206: 2 got dao
10-16 09:17:06.206: 2 start call batch task
10-16 09:17:06.216: 3 start initializing batch_task
10-16 09:17:06.326: 121 finished initializing batchtask  
10-16 09:17:06.836: 623 end batch task

2.3.4

10-16 09:20:00.355: 0 getting dao
10-16 09:20:00.355: 1 got dao
10-16 09:20:00.355: 1 start call batch task
10-16 09:20:00.355: 1 start initializing batch_task
10-16 09:20:00.435: 87 finished initializing batchtask  
10-16 09:20:00.445: 96 end batch task 

As you can see on ICS takes creating much more time.

What should I do to get the similar performance on ICS?

Gray
  • 115,027
  • 24
  • 293
  • 354
ba-res-ba
  • 150
  • 1
  • 9
  • So createOrUpdate is slow but create is the same speed? – Gray Oct 16 '12 at 12:35
  • Is this running on a device or in a simulator? – Gray Oct 16 '12 at 12:36
  • no speed difference between createOrUpdate and create.. – ba-res-ba Oct 16 '12 at 12:36
  • all of these results came from real device... – ba-res-ba Oct 16 '12 at 12:37
  • I checked databases on the two device, and the difference was the journal mode. On 2.3.4 wal, and on ICS (after update) truncate. I'm almost sure, slow performance caused by journal mode. No I'm trying to find the way how to change in ormlite. – ba-res-ba Oct 16 '12 at 12:53
  • You are trying to find a way to increase performance through ORMLite when it looks like it a SQLite setting issue? Do you want to turn off the journal mode through ORMLite? – Gray Oct 16 '12 at 13:00
  • The problem came after ICS update, I didn't change the journal mode. I 'm just trying to set back to wal through ormlite.. – ba-res-ba Oct 16 '12 at 13:02

2 Answers2

3

So after some back and forth in the comments, it turns out that the performance differences in Android ICS may be due to the fact that by default, in that version, SQLite may be running in "TRUNCATE" journal mode. From the Sqlite docs:

The TRUNCATE journaling mode commits transactions by truncating the rollback journal to zero-length instead of deleting it. On many systems, truncating a file is much faster than deleting the file since the containing directory does not need to be changed.

2.3.4 in comparison runs it in Write-Ahead-Logging (WAL) mode. I guess WAL is faster.

To change the journal in ORMLite, you'd do (I guess) something like the following:

someDao.rawExecute("PRAGMA journal_mode = WAL;");

See the Sqlite PRAGMA docs for more examples.

Gray
  • 115,027
  • 24
  • 293
  • 354
1

Finally, I found the solution:

getHelper().getDao();
SQLiteDatabase db = getHelper().getWritableDatabase();
Cursor cursor = db.rawQuery("PRAGMA journal_mode = WAL;", null);

only this way worked.

Other additional information to this issue:

  • I have 2 HTC Sensation, both are updated to ICS, so to 4.0.3
  • But software numbers are different!! (3.33.401.53, and 3.33.401.6), and no available updates on the devices (that's weird). I don't really understand what happened, maybe they changed the default journal mode between the build?

So, if you have experince slow database functions, check first journal mode on db. Thanks Gray, for your help.

Gray
  • 115,027
  • 24
  • 293
  • 354
ba-res-ba
  • 150
  • 1
  • 9
  • 4
    Was there a reason why my answer didn't answer your question? Either way, you should accept one of these. – Gray Jan 19 '13 at 21:13