[libcxx-commits] [PATCH] D154702: [libc++] [DO NOT MERGE] benchmark stop_token and use std::mutex in the implementation of stop_token

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 7 06:06:53 PDT 2023


ldionne added a comment.

This is actually quite nice! The second test (`libcxx/benchmarks/stop_token.async_shutdown.bench.cpp`) is the one that's more realistic (by far), so IMO it's the one that we should try to optimize for.

However, here's the timings I got on my arm64 mac studio:

With `std::atomic`:
`stop_token.async_shutdown.pass.cpp`: Total iterations of 20 threads for 10s was 3 100 911
`stop_token.jthread.pass.cpp`: Thread did 1 434 114 717 callback registration/deregistration in 30s

With `std::mutex`:
`stop_token.async_shutdown.pass.cpp`: Total iterations of 20 threads for 10s was 228 318 798
`stop_token.jthread.pass.cpp`: Thread did 1 618 248 541 callback registration/deregistration in 30s

This is rather bad. I think there's probably a significant problem with the implementation of our atomic notify functions. I think we need to figure out that bug before we can draw any conclusions about `stop_token`, since the current state is just bonkers.



================
Comment at: libcxx/benchmarks/stop_token.async_shutdown.bench.cpp:1
+//===----------------------------------------------------------------------===//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
----------------
We should modify these benchmarks to instead use GoogleBenchmark and time how long it takes to do N registrations.


================
Comment at: libcxx/benchmarks/stop_token.async_shutdown.bench.cpp:56-59
+      auto release_on_exit = on_scope_exit([&]() {
+        ready = true;
+        ready.notify_all();
+      });
----------------



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154702/new/

https://reviews.llvm.org/D154702



More information about the libcxx-commits mailing list