Use appropriate QoS classes throughout the codebase

This commit is contained in:
Luna Razzaghipour 2023-05-25 20:55:42 +10:00
parent 2924fd2213
commit d0b001eed2
No known key found for this signature in database
9 changed files with 20 additions and 19 deletions

View File

@ -90,7 +90,7 @@ pub fn spawn(
) -> FlycheckHandle {
let actor = FlycheckActor::new(id, sender, config, workspace_root);
let (sender, receiver) = unbounded::<StateChange>();
let thread = stdx::thread::Builder::new(stdx::thread::QoSClass::Default)
let thread = stdx::thread::Builder::new(stdx::thread::QoSClass::Utility)
.name("Flycheck".to_owned())
.spawn(move || actor.run(receiver))
.expect("failed to spawn thread");
@ -409,7 +409,7 @@ fn spawn(mut command: Command) -> std::io::Result<CargoHandle> {
let (sender, receiver) = unbounded();
let actor = CargoActor::new(sender, stdout, stderr);
let thread = stdx::thread::Builder::new(stdx::thread::QoSClass::Default)
let thread = stdx::thread::Builder::new(stdx::thread::QoSClass::Utility)
.name("CargoHandle".to_owned())
.spawn(move || actor.run())
.expect("failed to spawn thread");

View File

@ -81,7 +81,7 @@ enum ParallelPrimeCacheWorkerProgress {
let worker = prime_caches_worker.clone();
let db = db.snapshot();
stdx::thread::Builder::new(stdx::thread::QoSClass::Default)
stdx::thread::Builder::new(stdx::thread::QoSClass::Utility)
.allow_leak(true)
.spawn(move || Cancelled::catch(|| worker(db)))
.expect("failed to spawn thread");

View File

@ -85,7 +85,7 @@ fn try_main(flags: flags::RustAnalyzer) -> Result<()> {
// will make actions like hitting enter in the editor slow.
// rust-analyzer does not block the editors render loop,
// so we dont use User Interactive.
with_extra_thread("LspServer", stdx::thread::QoSClass::Default, run_server)?;
with_extra_thread("LspServer", stdx::thread::QoSClass::UserInitiated, run_server)?;
}
flags::RustAnalyzerCmd::Parse(cmd) => cmd.run()?,
flags::RustAnalyzerCmd::Symbols(cmd) => cmd.run()?,

View File

@ -88,7 +88,8 @@ pub(crate) fn on_sync<R>(
self
}
/// Dispatches the request onto thread pool
/// Dispatches a non-latency-sensitive request onto the thread pool
/// without retrying it if it panics.
pub(crate) fn on_no_retry<R>(
&mut self,
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
@ -103,7 +104,7 @@ pub(crate) fn on_no_retry<R>(
None => return self,
};
self.global_state.task_pool.handle.spawn(QoSClass::Default, {
self.global_state.task_pool.handle.spawn(QoSClass::Utility, {
let world = self.global_state.snapshot();
move || {
let result = panic::catch_unwind(move || {
@ -124,7 +125,7 @@ pub(crate) fn on_no_retry<R>(
self
}
/// Dispatches the request onto thread pool
/// Dispatches a non-latency-sensitive request onto the thread pool.
pub(crate) fn on<R>(
&mut self,
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
@ -134,7 +135,7 @@ pub(crate) fn on<R>(
R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug,
R::Result: Serialize,
{
self.on_with_qos::<R>(QoSClass::Default, f)
self.on_with_qos::<R>(QoSClass::Utility, f)
}
/// Dispatches a latency-sensitive request onto the thread pool.
@ -147,7 +148,7 @@ pub(crate) fn on_latency_sensitive<R>(
R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug,
R::Result: Serialize,
{
self.on_with_qos::<R>(QoSClass::Default, f)
self.on_with_qos::<R>(QoSClass::UserInitiated, f)
}
pub(crate) fn finish(&mut self) {

View File

@ -291,7 +291,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
}
Ok(())
};
state.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Default, move |_| {
state.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Utility, move |_| {
if let Err(e) = std::panic::catch_unwind(task) {
tracing::error!("flycheck task panicked: {e:?}")
}

View File

@ -397,7 +397,7 @@ fn prime_caches(&mut self, cause: String) {
tracing::debug!(%cause, "will prime caches");
let num_worker_threads = self.config.prime_caches_num_threads();
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Default, {
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Utility, {
let analysis = self.snapshot().analysis;
move |sender| {
sender.send(Task::PrimeCaches(PrimeCachesProgress::Begin)).unwrap();
@ -787,7 +787,10 @@ fn update_diagnostics(&mut self) {
tracing::trace!("updating notifications for {:?}", subscriptions);
let snapshot = self.snapshot();
self.task_pool.handle.spawn(stdx::thread::QoSClass::Default, move || {
// Diagnostics are triggered by the user typing
// so we want computing them to run at the User Initiated QoS.
self.task_pool.handle.spawn(stdx::thread::QoSClass::UserInitiated, move || {
let _p = profile::span("publish_diagnostics");
let diagnostics = subscriptions
.into_iter()

View File

@ -185,7 +185,7 @@ pub(crate) fn current_status(&self) -> lsp_ext::ServerStatusParams {
pub(crate) fn fetch_workspaces(&mut self, cause: Cause) {
tracing::info!(%cause, "will fetch workspaces");
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Default, {
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Utility, {
let linked_projects = self.config.linked_projects();
let detached_files = self.config.detached_files().to_vec();
let cargo_config = self.config.cargo();
@ -260,7 +260,7 @@ pub(crate) fn fetch_build_data(&mut self, cause: Cause) {
tracing::info!(%cause, "will fetch build data");
let workspaces = Arc::clone(&self.workspaces);
let config = self.config.cargo();
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Default, move |sender| {
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Utility, move |sender| {
sender.send(Task::FetchBuildData(BuildDataProgress::Begin)).unwrap();
let progress = {
@ -280,7 +280,7 @@ pub(crate) fn fetch_proc_macros(&mut self, cause: Cause, paths: Vec<ProcMacroPat
let dummy_replacements = self.config.dummy_replacements().clone();
let proc_macro_clients = self.proc_macro_clients.clone();
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Default, move |sender| {
self.task_pool.handle.spawn_with_sender(stdx::thread::QoSClass::Utility, move |sender| {
sender.send(Task::LoadProcMacros(ProcMacroProgress::Begin)).unwrap();
let dummy_replacements = &dummy_replacements;

View File

@ -155,8 +155,6 @@ pub enum QoSClass {
/// performance, responsiveness and efficiency.
Utility,
Default,
/// TLDR: tasks that block using your app
///
/// Contract:
@ -234,7 +232,6 @@ pub(super) fn set_current_thread_qos_class(class: QoSClass) {
let c = match class {
QoSClass::UserInteractive => libc::qos_class_t::QOS_CLASS_USER_INTERACTIVE,
QoSClass::UserInitiated => libc::qos_class_t::QOS_CLASS_USER_INITIATED,
QoSClass::Default => libc::qos_class_t::QOS_CLASS_DEFAULT,
QoSClass::Utility => libc::qos_class_t::QOS_CLASS_UTILITY,
QoSClass::Background => libc::qos_class_t::QOS_CLASS_BACKGROUND,
};

View File

@ -34,7 +34,7 @@ impl loader::Handle for NotifyHandle {
fn spawn(sender: loader::Sender) -> NotifyHandle {
let actor = NotifyActor::new(sender);
let (sender, receiver) = unbounded::<Message>();
let thread = stdx::thread::Builder::new(stdx::thread::QoSClass::Default)
let thread = stdx::thread::Builder::new(stdx::thread::QoSClass::Utility)
.name("VfsLoader".to_owned())
.spawn(move || actor.run(receiver))
.expect("failed to spawn thread");