21 Aug 2012 12:06 PM #1
How can I Batch Operations?
I have a bunch of objects that I want to create records from and save to localStorage. Model + Store + Proxy... all good there, but if I have a LOT of objects to save (e.g. 5000), how can I make sure the records all get built, THEN saved all at once to localStorage really quickly?
My guess is that if I do it in batch, localStorage writes will block the thread for less time.
23 Aug 2012 4:31 AM #2
- Join Date
- Mar 2007
- Gainesville, FL
- Vote Rating
Don't have autoSync set to true. Create your records and then do a store.sync() and it will sync all changes to the store at once.Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Software Engineer
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services firstname.lastname@example.org
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!
When posting code, please use BBCode's CODE tags.
25 Aug 2012 12:07 AM #3
Thanks @Mitchell, but I'm not seeing any improvement when I follow your advice. Is there something else I could be doing wrong? Here are the numbers I'm seeing in Chrome on my year-old MacBook Pro (i7). Adding just over 3000 records with about 5 fields per record is taking:
~60 seconds with autoSync turned on
~60 seconds if I turn autoSync off, add the records, then sync
~1/4 of a second with no syncing at all
At just over 50 records/second, I have to assume I'm doing something horribly wrong.
26 Aug 2012 4:47 PM #4
@Mitchell, I created a test case that better represents what I'm talking about. It compares the performance of the OOTB behavior (for each record, encode, then write) against pre-encoding all of the key->value records in a batch then writing them all at once. I would be grateful for any comments or advice.
29 Aug 2012 5:01 AM #5