I have to parse a pretty big XML file (different between in regards to a hundred kilobytes and many hundred kilobytes), which I am doing using Xml#parse(String, ContentHandler). I am presently testing this having a 152KB file.

Throughout parsing, I additionally place the information within an SQLite database using calls like the following: getWritableDatabase().insert(TABLE_NAME, "_id", values). All this together takes about 80 seconds for that 152KB test file (which will come lower to placing roughly 200 rows).

After I comment out all place claims (but leave in anything else, for example creating ContentValues etc.) exactly the same file takes only 23 seconds.

Could it be normal for that database procedures to possess this type of large overhead? Can One do anything whatsoever about this?

You want to do batch card inserts.


for (entry : listOfEntries) {

That elevated the rate of card inserts during my applications very.

@Yuku provided a really interesting blog publish: Android using inserthelper for faster insertions into sqlite database

When the table comes with an index onto it, consider shedding it just before placing the records after which adding it back after you have commited your records.

Producing the sql place statement helps quicken things. Additionally, it may require more effort to shoreline everything up and stop possible injection becasue it is now all in your shoulders.

Another approach which could also quicken things may be the under-recorded android.database.DatabaseUtils.InsertHelper class. My understanding is it really systems put together place claims. Going from non-put together transacted card inserts to put together transacted card inserts involved a 3x grow in speed (2ms per place to .6ms per place) for my large (200K+ records) but simple SQLite card inserts.

Sample code:

SQLiteDatabse db = getWriteableDatabase();

//use the db you would normally use for db.insert, and the "table_name"
//is the same one you would use in db.insert()
InsertHelper iHelp = new InsertHelper(db, "table_name");

//Get the indices you need to bind data to
//Similar to Cursor.getColumnIndex("col_name");                 
int first_index = iHelp.getColumnIndex("first");
int last_index = iHelp.getColumnIndex("last");

   for(int i=0 ; i<num_things ; ++i)
       //need to tell the helper you are inserting (rather than replacing)

       //do the equivalent of ContentValues.put("field","value") here
       iHelp.bind(first_index, thing_1);
       iHelp.bind(last_index, thing_2);

       //the db.insert() equilvalent