Use one task per iteration in parallel_for_loop.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 15 Nov 2016 22:13:16 +0000 (22:13 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 15 Nov 2016 22:13:16 +0000 (22:13 +0000)
This seems far more natural. A user can create larger chunks if the
overhead is too large.

With this linking xul with "--threads --build-id=sha1 goes from
13.938177535 to 11.035953538 seconds on linux.

llvm-svn: 287042

lld/include/lld/Core/Parallel.h

index 0ceb3e6..eaf1390 100644 (file)
@@ -284,12 +284,8 @@ void parallel_for_each(Iterator begin, Iterator end, Func func) {
 template <class Iterator, class Func>
 void parallel_for_each(Iterator begin, Iterator end, Func func) {
   TaskGroup tg;
-  ptrdiff_t taskSize = 1024;
-  while (taskSize <= std::distance(begin, end)) {
-    tg.spawn([=, &func] { std::for_each(begin, begin + taskSize, func); });
-    begin += taskSize;
-  }
-  std::for_each(begin, end, func);
+  for (; begin != end; ++begin)
+    tg.spawn([=, &func] { func(*begin); });
 }
 #endif
 } // end namespace lld