diff options
author | Aleksey Kladov <[email protected]> | 2020-01-26 11:02:56 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-01-26 13:15:57 +0000 |
commit | 493a903f226d148fec4b539f65b78a408e4dcb2c (patch) | |
tree | ae660f8813688bde603f8c7b6b1ec5f4ae94c36e | |
parent | 40109941db20180eb71b70c23c578fed5244bd74 (diff) |
Bump main thread priority on windows
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/Cargo.toml | 3 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 19 |
3 files changed, 23 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock index 07fff9af5..8e320458b 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1079,6 +1079,7 @@ dependencies = [ | |||
1079 | "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1079 | "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1080 | "test_utils 0.1.0", | 1080 | "test_utils 0.1.0", |
1081 | "threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1081 | "threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1082 | "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1082 | ] | 1083 | ] |
1083 | 1084 | ||
1084 | [[package]] | 1085 | [[package]] |
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index 5df0496dd..fdf81ed87 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -30,6 +30,9 @@ env_logger = { version = "0.7.1", default-features = false } | |||
30 | ra_cargo_watch = { path = "../ra_cargo_watch" } | 30 | ra_cargo_watch = { path = "../ra_cargo_watch" } |
31 | either = "1.5" | 31 | either = "1.5" |
32 | 32 | ||
33 | [target.'cfg(windows)'.dependencies] | ||
34 | winapi = "0.3" | ||
35 | |||
33 | [dev-dependencies] | 36 | [dev-dependencies] |
34 | tempfile = "3" | 37 | tempfile = "3" |
35 | test_utils = { path = "../test_utils" } | 38 | test_utils = { path = "../test_utils" } |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 315f4a4d6..15bf519c9 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -57,6 +57,25 @@ pub fn main_loop( | |||
57 | ) -> Result<()> { | 57 | ) -> Result<()> { |
58 | log::info!("server_config: {:#?}", config); | 58 | log::info!("server_config: {:#?}", config); |
59 | 59 | ||
60 | // Windows scheduler implements priority boosts: if thread waits for an | ||
61 | // event (like a condvar), and event fires, priority of the thread is | ||
62 | // temporary bumped. This optimization backfires in our case: each time the | ||
63 | // `main_loop` schedules a task to run on a threadpool, the worker threads | ||
64 | // gets a higher priority, and (on a machine with fewer cores) displaces the | ||
65 | // main loop! We work-around this by marking the main loop as a | ||
66 | // higher-priority thread. | ||
67 | // | ||
68 | // https://docs.microsoft.com/en-us/windows/win32/procthread/scheduling-priorities | ||
69 | // https://docs.microsoft.com/en-us/windows/win32/procthread/priority-boosts | ||
70 | // https://github.com/rust-analyzer/rust-analyzer/issues/2835 | ||
71 | #[cfg(windows)] | ||
72 | unsafe { | ||
73 | use winapi::um::processthreadsapi::*; | ||
74 | let thread = GetCurrentThread(); | ||
75 | let thread_priority_above_normal = 1; | ||
76 | SetThreadPriority(thread, thread_priority_above_normal); | ||
77 | } | ||
78 | |||
60 | let mut loop_state = LoopState::default(); | 79 | let mut loop_state = LoopState::default(); |
61 | let mut world_state = { | 80 | let mut world_state = { |
62 | let feature_flags = { | 81 | let feature_flags = { |