8000 Add a parallelism abstraction library by elliottt · Pull Request #8880 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add a parallelism abstraction library #8880

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 3 commits into from
May 19, 2025
Merged

Conversation

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

We have a few common patterns for parallelism in Sorbet, and it would be nice to simplify their use. This PR introduces the Parallel class, and a first implementation of one of these patterns: iterate. This template wraps up a common use of WorkerPool::multiplexJobWait where we apply a function to the contents of a vector in parallel, but with some additional guards that avoid the pool for sufficiently small inputs.

Initial tracing looks good, in that I don't see the visibility checker occasionally spiking in duration on the fast path.

Motivation

I've been seeing strange overhead from using concurrency on small inputs that makes me think that we should avoid it when possible. This shows up commonly on the fast path in LSP, where single file edits are the norm.

Test plan

Existing tests.

@elliottt elliottt changed the title Add a new library for concurrency patterns Add a concurrency abstractions library May 16, 2025
if constexpr (buildPackageDB) {
if (gs.packageDB().enforceLayering()) {
ComputePackageSCCs::run(gs);
}
}

workers.multiplexJobWait("rewritePackagesAndFiles", [&gs = as_const(gs), &files, taskq]() {
Timer timeit(gs.tracer(), "packager.rewritePackagesAndFilesWorker");
Copy link
Contributor

Choose a reason for hiding this comment

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

I am sad that we lose the ability to add timings for individual workers, but maybe it's not really valuable to know how long the workers take, and what you really care about would be accomplished with:

{
  Timer timeit(gs.tracer, "work");
  workers.multiplexJobWait(...);
}

instead?

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 think I agree with that. We can always put timers into the body of the worker to know how long the individual iterations take, and use the span around the whole job as a reference.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wait so do we lose anything?

Could we not have kept the behavior by putting the Workers timer in the body?

I'm trying to understand the change in what's not possible with this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Putting it in the body means we'll see many small spans on the thread when viewing the trace, instead of one long span that covers the duration of the work. I think this is an okay tradeoff, as we can wrap one big span around the use of iterate, and then see spans for work items on the threads.

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh, yeah I don't think I care too much about that.

@elliottt elliottt force-pushed the trevor/concurrency-patterns branch from 6de25a0 to 20fb82f Compare May 16, 2025 16:27
@elliottt elliottt marked this pull request as ready for review May 16, 2025 16:27
@elliottt elliottt requested a review from a team as a code owner May 16, 2025 16:27
@elliottt elliottt requested review from froydnj and jez and removed request for a team May 16, 2025 16:27
@elliottt elliottt changed the title Add a concurrency abstractions library Add a parallelism abstraction library May 16, 2025
@elliottt elliottt merged commit 403b467 into master May 19, 2025
14 checks passed
@elliottt elliottt deleted the trevor/concurrency-patterns branch May 19, 2025 18:00
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.

3 participants
0