Skip to content

Add group.OrderedParallel

Warren Gifford requested to merge cc/ordered-pargroup into main

Created by: camdencheek

This mints a new lib/group package and creates group.OrderedParallel.

The purpose of group.OrderedParallel is to solve the problem of executing an expensive task on every event in an ordered stream. This has come up a few times in search backend code, but generics now allow us to solve this in a reuseable and more performant mannner.

An example of when this is useful is fetching file content for each result in a compute stream. It's very slow to do that serially, but a naive parallelization loses the order of results. I plan to make a followup PR using group.OrderedParallel to improve performance there.

Note that this design can be used for batches of events too, but a normal parallel executor over a finite set of tasks can't be used for a stream without adding latency.

Perf-wise, this adds ~1us of overhead to each task due to the channel operations.

Split out of https://github.com/sourcegraph/sourcegraph/pull/35509

Test plan

Added a few tests and ran them with -race and -count 100 to catch any race conditions.

Merge request reports

Loading