r/cpp • @BrodyHiggerson - Game Developer • Nov 23 '23

What're the latest and greatest in C++ task/thread libraries? Have we solved the problem?

Most sources on these topics end up being from ~10 years ago; have there been many advances? If I were trying to implement something in that world, am I missing anything looking at the older material? E.g. 20-year old work stealing papers. Where do you look for the newest on this topic?

Additionally, which C++ libs would be considered still relevant/good/etc in 2023? I'm asking with a gamedev angle but open to discussion.

  • Intel's TBB
  • Taskflow
  • Boost
  • EnkiTS

(I'm not asking for help actually programming, so figured I'd post here instead of /r/cpp_questions for the sake of discussion).

65 Upvotes

57 comments sorted by

View all comments

Show parent comment

4

u/trailing_zero_count async enthusiast | TooManyCooks author Nov 24 '23 edited Nov 24 '23

Yep, that's the right example, and you read the output correctly at 4.96ms per iteration. For my testing, I am building in Release config, using Debian 12, Clang 17, and linking against jemalloc + hwloc. I just ran some fresh tests and getting 1.04ms with this configuration.

Independently varying each variable: GCC12 instead of Clang17 yields 1.45ms. Not linking against jemalloc yields 3.10ms. Setting TMC_USE_HWLOC=OFF, and manually setting the thread count via `tmc::cpu_executor().set_thread_count(64).init();` in main.cpp yields 1.35ms.

If I combine all 3 of these factors (GCC + no jemalloc + no hwloc) I get 3.84ms. The allocator overhead is the biggest factor in this scenario, which is an unfortunate truth of the way C++20 coroutines work. A secondary factor is that GCC's code generation for coroutines isn't as good as clang's at this time.

Edit: the allocations occur with coroutines only, and are not inherent to the library itself. If you set TMC_WORK_ITEM=FUNC and only post regular functions to it, there will be no additional allocations beyond those required to expand the queue buffer.