Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d0b001e

Browse files
committed
Use appropriate QoS classes throughout the codebase
1 parent 2924fd2 commit d0b001e

File tree

9 files changed

+20
-19
lines changed

9 files changed

+20
-19
lines changed

crates/flycheck/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl FlycheckHandle {
9090
) -> FlycheckHandle {
9191
let actor = FlycheckActor::new(id, sender, config, workspace_root);
9292
let (sender, receiver) = unbounded::<StateChange>();
93-
let thread = stdx::thread::Builder::new(stdx::thread::QoSClass::Default)
93+
let thread = stdx::thread::Builder::new(stdx::thread::QoSClass::Utility)
9494
.name("Flycheck".to_owned())
9595
.spawn(move || actor.run(receiver))
9696
.expect("failed to spawn thread");
@@ -409,7 +409,7 @@ impl CargoHandle {
409409

410410
let (sender, receiver) = unbounded();
411411
let actor = CargoActor::new(sender, stdout, stderr);
412-
let thread = stdx::thread::Builder::new(stdx::thread::QoSClass::Default)
412+
let thread = stdx::thread::Builder::new(stdx::thread::QoSClass::Utility)
413413
.name("CargoHandle".to_owned())
414414
.spawn(move || actor.run())
415415
.expect("failed to spawn thread");

crates/ide/src/prime_caches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub(crate) fn parallel_prime_caches(
8181
let worker = prime_caches_worker.clone();
8282
let db = db.snapshot();
8383

84-
stdx::thread::Builder::new(stdx::thread::QoSClass::Default)
84+
stdx::thread::Builder::new(stdx::thread::QoSClass::Utility)
8585
.allow_leak(true)
8686
.spawn(move || Cancelled::catch(|| worker(db)))
8787
.expect("failed to spawn thread");

crates/rust-analyzer/src/bin/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn try_main(flags: flags::RustAnalyzer) -> Result<()> {
8585
// will make actions like hitting enter in the editor slow.
8686
// rust-analyzer does not block the editor’s render loop,
8787
// so we don’t use User Interactive.
88-
with_extra_thread("LspServer", stdx::thread::QoSClass::Default, run_server)?;
88+
with_extra_thread("LspServer", stdx::thread::QoSClass::UserInitiated, run_server)?;
8989
}
9090
flags::RustAnalyzerCmd::Parse(cmd) => cmd.run()?,
9191
flags::RustAnalyzerCmd::Symbols(cmd) => cmd.run()?,

crates/rust-analyzer/src/dispatch.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ impl<'a> RequestDispatcher<'a> {
8888
self
8989
}
9090

91-
/// Dispatches the request onto thread pool
91+
/// Dispatches a non-latency-sensitive request onto the thread pool
92+
/// without retrying it if it panics.
9293
pub(crate) fn on_no_retry<R>(
9394
&mut self,
9495
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
@@ -103,7 +104,7 @@ impl<'a> RequestDispatcher<'a> {
103104
None => return self,
104105
};
105106

106-
self.global_state.task_pool.handle.spawn(QoSClass::Default, {
107+
self.global_state.task_pool.handle.spawn(QoSClass::Utility, {
107108
let world = self.global_state.snapshot();
108109
move || {
109110
let result = panic::catch_unwind(move || {
@@ -124,7 +125,7 @@ impl<'a> RequestDispatcher<'a> {
124125
self
125126
}
126127

127-
/// Dispatches the request onto thread pool
128+
/// Dispatches a non-latency-sensitive request onto the thread pool.
128129
pub(crate) fn on<R>(
129130
&mut self,
130131
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
@@ -134,7 +135,7 @@ impl<'a> RequestDispatcher<'a> {
134135
R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug,
135136
R::Result: Serialize,
136137
{
137-
self.on_with_qos::<R>(QoSClass::Default, f)
138+
self.on_with_qos::<R>(QoSClass::Utility, f)
138139
}
139140

140141
/// Dispatches a latency-sensitive request onto the thread pool.
@@ -147,7 +148,7 @@ impl<'a> RequestDispatcher<'a> {
147148
R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug,
148149
R::Result: Serialize,
149150
{
150-
self.on_with_qos::<R>(QoSClass::Default, f)
151+
self.on_with_qos::<R>(QoSClass::UserInitiated, f)
151152
}
152153

153154
pub(crate) fn finish(&mut self) {

crates/rust-analyzer/src/handlers/notification.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
291291
}
292292
Ok(())
293293
};
294-
state.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Default, move |_| {
294+
state.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Utility, move |_| {
295295
if let Err(e) = std::panic::catch_unwind(task) {
296296
tracing::error!("flycheck task panicked: {e:?}")
297297
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl GlobalState {
397397
tracing::debug!(%cause, "will prime caches");
398398
let num_worker_threads = self.config.prime_caches_num_threads();
399399

400-
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Default, {
400+
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Utility, {
401401
let analysis = self.snapshot().analysis;
402402
move |sender| {
403403
sender.send(Task::PrimeCaches(PrimeCachesProgress::Begin)).unwrap();
@@ -787,7 +787,10 @@ impl GlobalState {
787787
tracing::trace!("updating notifications for {:?}", subscriptions);
788788

789789
let snapshot = self.snapshot();
790-
self.task_pool.handle.spawn(stdx::thread::QoSClass::Default, move || {
790+
791+
// Diagnostics are triggered by the user typing
792+
// so we want computing them to run at the User Initiated QoS.
793+
self.task_pool.handle.spawn(stdx::thread::QoSClass::UserInitiated, move || {
791794
let _p = profile::span("publish_diagnostics");
792795
let diagnostics = subscriptions
793796
.into_iter()

crates/rust-analyzer/src/reload.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl GlobalState {
185185
pub(crate) fn fetch_workspaces(&mut self, cause: Cause) {
186186
tracing::info!(%cause, "will fetch workspaces");
187187

188-
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Default, {
188+
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Utility, {
189189
let linked_projects = self.config.linked_projects();
190190
let detached_files = self.config.detached_files().to_vec();
191191
let cargo_config = self.config.cargo();
@@ -260,7 +260,7 @@ impl GlobalState {
260260
tracing::info!(%cause, "will fetch build data");
261261
let workspaces = Arc::clone(&self.workspaces);
262262
let config = self.config.cargo();
263-
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Default, move |sender| {
263+
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Utility, move |sender| {
264264
sender.send(Task::FetchBuildData(BuildDataProgress::Begin)).unwrap();
265265

266266
let progress = {
@@ -280,7 +280,7 @@ impl GlobalState {
280280
let dummy_replacements = self.config.dummy_replacements().clone();
281281
let proc_macro_clients = self.proc_macro_clients.clone();
282282

283-
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Default, move |sender| {
283+
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Utility, move |sender| {
284284
sender.send(Task::LoadProcMacros(ProcMacroProgress::Begin)).unwrap();
285285

286286
let dummy_replacements = &dummy_replacements;

crates/stdx/src/thread.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ pub enum QoSClass {
155155
/// performance, responsiveness and efficiency.
156156
Utility,
157157

158-
Default,
159-
160158
/// TLDR: tasks that block using your app
161159
///
162160
/// Contract:
@@ -234,7 +232,6 @@ mod imp {
234232
let c = match class {
235233
QoSClass::UserInteractive => libc::qos_class_t::QOS_CLASS_USER_INTERACTIVE,
236234
QoSClass::UserInitiated => libc::qos_class_t::QOS_CLASS_USER_INITIATED,
237-
QoSClass::Default => libc::qos_class_t::QOS_CLASS_DEFAULT,
238235
QoSClass::Utility => libc::qos_class_t::QOS_CLASS_UTILITY,
239236
QoSClass::Background => libc::qos_class_t::QOS_CLASS_BACKGROUND,
240237
};

crates/vfs-notify/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl loader::Handle for NotifyHandle {
3434
fn spawn(sender: loader::Sender) -> NotifyHandle {
3535
let actor = NotifyActor::new(sender);
3636
let (sender, receiver) = unbounded::<Message>();
37-
let thread = stdx::thread::Builder::new(stdx::thread::QoSClass::Default)
37+
let thread = stdx::thread::Builder::new(stdx::thread::QoSClass::Utility)
3838
.name("VfsLoader".to_owned())
3939
.spawn(move || actor.run(receiver))
4040
.expect("failed to spawn thread");

0 commit comments

Comments
 (0)