Proposal: Deprecate Tokio's LocalSet #6741
Labels
A-tokio
Area: The main tokio crate
C-proposal
Category: a proposal and request for comments
M-runtime
Module: tokio/runtime
This is a proposal to deprecate the Tokio
LocalSet
abstraction in favor of a newLocalRuntime
type. Currently, to spawn!Send
tasks on Tokio you must use a combination of a current-thread runtime andLocalSet
to make that work. However, tasks on aLocalSet
are separate from the rest of the runtime in an uncomfortable way. For example:LocalSet
cantokio::spawn
to get onto the runtime, but once you're on the runtime, you can no longerspawn_local
to get back into theLocalSet
.LocalSet
behave like a single task usingFuturesUnordered
, so various runtime options such asevent_interval
behave in a very surprising way by counting many tasks as a single task.LocalSet
has been shown to involve considerable performance overhead compared to unsafely spawning the!Send
tasks onto a current-thread runtime.Because of the above, I have proposed to add a new type called
LocalRuntime
which will be the replacement. Please see #6739 for the feature request to add that type. However, beyond just adding a newLocalRuntime
type, I am also proposing to formally deprecate theLocalSet
type. That's this issue.Specifically, I am proposing the following course of action:
LocalRuntime
type, which would close #6739.#[deprecated]
to theLocalSet
type, so that existing users ofLocalSet
receive a warning that recommendsLocalRuntime
.LocalSet
working forever.I believe that all existing uses of
LocalSet
can be replaced either by the newLocalRuntime
or byFuturesUnordered
. The advantage of this approach is that the current design ofLocalSet
make it impossible to add some features without having them be really confusing:LocalSet
. This is confusing.block_on
, which means thatLocalSet
tasks are completely invisible to task dumps.In both cases, supporting
LocalSet
well is very difficult. As long asLocalSet
remains a first-class citizen, it is difficult to introduce new features that affect all tasks without having confusing behavior whenLocalSet
is used.Note that
spawn_local
is not being deprecated. The intent is that it will work together withLocalRuntime
.Some alternative options:
LocalRuntime
but do not deprecateLocalSet
. This provides a way to work around the performance issues ofLocalSet
, but ultimately it is still difficult to introduce new features that affect all tasks on the runtime.The purpose of this issue is to gather feedback from users of
LocalSet
. Please post your experience below. I am especially interested in use-cases that cannot be replaced byLocalRuntime
orFuturesUnordered
.The text was updated successfully, but these errors were encountered: