-
-
Notifications
You must be signed in to change notification settings - Fork 572
Allow Dispatcher to be configured for single-producer scenarios #2768
Description
Right now, Dispatcher somewhat pessimistically assumes that you will be using it from multiple producers simultaneously, and the actions you're enqueuing might be very lengthy. This forces its implementation to stripe internally, as well as .start every action it is given, both of which sacrifice ordering properties entirely. Additionally, this adds some extra overhead relative to what we theoretically could do if we had a guarantee that only a single fiber was producer to a given Dispatcher.
We should add this as a configurable mode. In particular, what this mode would do is suppress the striping and the starting. Users would not be able to share such Dispatchers across fibers (or they could, but it would be very slow to do so), but if they stay affine to a single fiber the results would be better performance and guaranteed ordering in the sense that fa.unsafeRunAndForget(); fb.unsafeRunAndForget() would produce the same outcome as fa.guarantee(fb).unsafeRunAndForget().