8000 Avoid absl::BlockingCounter use for the single-threaded WorkerPool by elliottt · Pull Request #8852 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Avoid absl::BlockingCounter use for the single-threaded WorkerPool #8852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 8, 2025

Conversation

elliottt
Copy link
Collaborator
@elliottt elliottt commented May 8, 2025

In some uses of WorkerPool::multiplexJob we allocate an absl::BlockingCounter and wait on it after the call to multiplexJob to ensure that all workers finished processing our job. This is a fine pattern, but in the case of a worker pool created with 0 workers, the blocking counter is totally unneeded as multiplexJob will execute our task directly.

We can avoid the absl::BlockingCounter use entirely if we add a specialization of multiplexJob for this case specifically, and that's what this PR does. WorkerPool::multiplexJobWait manages the allocation and use of the counter in the multi-threaded case, and avoids it all when we're running single-threaded.

Motivation

Performance improvements when we're running with an empty worker pool, which happens frequently during slow path preemption in LSP.

Test plan

Existing tests.

@elliottt elliottt force-pushed the trevor/multiplex-wait branch from b84b6ba to 552168b Compare May 8, 2025 15:42
@elliottt elliottt changed the title Avoid mutex use for some single-threaded uses of WorkerPool Avoid absl::BlockingCounter use for the single-threaded WorkerPool May 8, 2025
@elliottt elliottt marked this pull request as ready for review May 8, 2025 15:50
@elliottt elliottt requested a review from a team as a code owner May 8, 2025 15:50
@elliottt elliottt requested review from jez and removed request for a team May 8, 2025 15:50
@elliottt elliottt force-pushed the trevor/multiplex-wait branch from 552168b to 23ae71f Compare May 8, 2025 15:52
@@ -14,6 +14,11 @@ class WorkerPool {
using Task = std::function<void()>;
static std::unique_ptr<WorkerPool> create(int size, spdlog::logger &logger);
virtual void multiplexJob(std::string_view taskName, Task t) = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we document this one too, something like

"does not block after launching the workers, usually useful so that the main thread can 8000 have a consumer queue that streams the results of the worker threads as they produce them"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely!

@@ -26,6 +26,7 @@ cc_library(
"//common/enforce_no_timer",
"//common/exception",
"//common/os",
"@com_google_absl//absl/synchronization",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know whether it's worth it to also remove the absl/synch dep from common/BUILD (or even whether it's possible).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give it a try!

@elliottt elliottt merged commit 4578f26 into master May 8, 2025
14 checks passed
@elliottt elliottt deleted the trevor/multiplex-wait branch May 8, 2025 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0