Skip to content

Commit 73afdba

Browse files
committed
do not use workers on small lists of pending objects
Preparing workers for parallel processing has quite a bit of setup overhead. It is therefore not worth doing unless there are enough objects to process to make the overhead worth it. This speeds up in particular the tests where only a handful of objects is imported per run.
1 parent 677b647 commit 73afdba

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/osmdata.cpp

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -302,25 +302,33 @@ class multithreaded_processor
302302
ids_queued, type, m_clones.size()));
303303

304304
util::timer_t timer;
305-
std::vector<std::future<void>> workers;
306305

307-
for (auto const &clone : m_clones) {
308-
workers.push_back(std::async(std::launch::async, run,
309-
std::cref(clone), &list, &m_mutex,
310-
function));
311-
}
312-
workers.push_back(
313-
std::async(std::launch::async, print_stats, &list, &m_mutex));
314-
315-
for (auto &worker : workers) {
316-
try {
317-
worker.get();
318-
} catch (...) {
319-
// Drain the queue, so that the other workers finish early.
320-
m_mutex.lock();
321-
list.clear();
322-
m_mutex.unlock();
323-
throw;
306+
if (ids_queued < 100) {
307+
for (auto const oid : list) {
308+
(m_clones[0].get()->*function)(oid);
309+
}
310+
m_clones[0]->sync();
311+
} else {
312+
std::vector<std::future<void>> workers;
313+
314+
for (auto const &clone : m_clones) {
315+
workers.push_back(std::async(std::launch::async, run,
316+
std::cref(clone), &list, &m_mutex,
317+
function));
318+
}
319+
workers.push_back(
320+
std::async(std::launch::async, print_stats, &list, &m_mutex));
321+
322+
for (auto &worker : workers) {
323+
try {
324+
worker.get();
325+
} catch (...) {
326+
// Drain the queue, so that the other workers finish early.
327+
m_mutex.lock();
328+
list.clear();
329+
m_mutex.unlock();
330+
throw;
331+
}
324332
}
325333
}
326334

0 commit comments

Comments
 (0)