[android-developers] Re: SQLite DB: insert VERY slow
On Sep 11, 12:10 pm, Mark Murphy mmur...@commonsware.com wrote: By default, each insert is its own transaction, involving individual flash writes, which gets slow. Batch the inserts (e.g., 100 to a transaction), and things will go more smoothly. Wow, thanks for the tip! I hadn't been bothering with transactions on my inserts (the data involved isn't that mission-critical), but adding them just now sped things up considerably. String -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: SQLite DB: insert VERY slow
SQLite DBs are very fast, it takes less than half a second to insert a record/records. 1000 records is a lot! I haven't seen your code but what you should do is: openDatabase once insert all records close DB Avoid open/close database 1000 times. Also the GC is probably very busy during the operation so look for optimizations(avoid unnecessary object creation, StringBuilder instead of String when appropiate, etc...) Hope this helps! Alberto On Sep 11, 4:41 am, ls02 agal...@audible.com wrote: I need to insert 1000 rows into SQLite DB. Each row has 12 columns, text and numbers, none is big. It takes literraly minutes to insert all 1000 items. I use SQLiteDatabase.insert to insert each row. What can I do to improve this performance? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: SQLite DB: insert VERY slow
Make sure you use transactions. In my situation, minutes became seconds when I did that. On Sep 11, 4:51 am, Albert albert8...@googlemail.com wrote: SQLite DBs are very fast, it takes less than half a second to insert a record/records. 1000 records is a lot! I haven't seen your code but what you should do is: openDatabase once insert all records close DB Avoid open/close database 1000 times. Also the GC is probably very busy during the operation so look for optimizations(avoid unnecessary object creation, StringBuilder instead of String when appropiate, etc...) Hope this helps! Alberto On Sep 11, 4:41 am, ls02 agal...@audible.com wrote: I need to insert 1000 rows into SQLite DB. Each row has 12 columns, text and numbers, none is big. It takes literraly minutes to insert all 1000 items. I use SQLiteDatabase.insert to insert each row. What can I do to improve this performance?- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: SQLite DB: insert VERY slow
On Sat, Sep 11, 2010 at 5:15 AM, Zsolt Vasvari zvasv...@gmail.com wrote: Make sure you use transactions. In my situation, minutes became seconds when I did that. Agreed. By default, each insert is its own transaction, involving individual flash writes, which gets slow. Batch the inserts (e.g., 100 to a transaction), and things will go more smoothly. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9 Available! -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en