From 82e2289f344cf4997ddfce7970c8d8cd9d550c14 Mon Sep 17 00:00:00 2001 From: Matt Vogt Date: Wed, 8 Jan 2014 18:09:12 -0800 Subject: [PATCH] [libcontacts] Append contacts in large batches Batched append slows down the overall throughput, but is necessary to give interactivity during startup with huge contact counts. With 10000 contacts, the penalty is less than 10% overall, and the app remains usable during the append period. --- src/seasidecache.cpp | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/seasidecache.cpp b/src/seasidecache.cpp index edee2cc..2f3298e 100644 --- a/src/seasidecache.cpp +++ b/src/seasidecache.cpp @@ -2311,21 +2311,35 @@ void SeasideCache::applyPendingContactUpdates() const bool partialFetch = !detailTypes.isEmpty(); QList &appendedContacts((*it).second); - appendContacts(appendedContacts, type, partialFetch, detailTypes); - - m_contactsToAppend.erase(it); - - // This list has been processed - have we finished populating the group? - if (type == FilterFavorites && (m_populateProgress != FetchFavorites)) { - makePopulated(FilterFavorites); - qDebug() << "Favorites queried in" << m_timer.elapsed() << "ms"; - } else if (type == FilterAll && (m_populateProgress != FetchMetadata)) { - makePopulated(FilterNone); - makePopulated(FilterAll); - qDebug() << "All queried in" << m_timer.elapsed() << "ms"; - } else if (type == FilterOnline && (m_populateProgress != FetchOnline)) { - makePopulated(FilterOnline); - qDebug() << "Online queried in" << m_timer.elapsed() << "ms"; + + const int maxBatchSize = 200; + const int minBatchSize = 50; + + if (appendedContacts.count() < maxBatchSize) { + // For a small number of contacts, append all at once + appendContacts(appendedContacts, type, partialFetch, detailTypes); + appendedContacts.clear(); + } else { + // Append progressively in batches + appendContacts(appendedContacts.mid(0, minBatchSize), type, partialFetch, detailTypes); + appendedContacts = appendedContacts.mid(minBatchSize); + } + + if (appendedContacts.isEmpty()) { + m_contactsToAppend.erase(it); + + // This list has been processed - have we finished populating the group? + if (type == FilterFavorites && (m_populateProgress != FetchFavorites)) { + makePopulated(FilterFavorites); + qDebug() << "Favorites queried in" << m_timer.elapsed() << "ms"; + } else if (type == FilterAll && (m_populateProgress != FetchMetadata)) { + makePopulated(FilterNone); + makePopulated(FilterAll); + qDebug() << "All queried in" << m_timer.elapsed() << "ms"; + } else if (type == FilterOnline && (m_populateProgress != FetchOnline)) { + makePopulated(FilterOnline); + qDebug() << "Online queried in" << m_timer.elapsed() << "ms"; + } } } else { QList, QList > >::iterator it = m_contactsToUpdate.begin();