aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-04 18:43:37 +0100
committerAleksey Kladov <[email protected]>2018-09-04 18:43:37 +0100
commitf87771092c5df9e9c07bcb5052e662bde0a0fa59 (patch)
tree9fd40d50ea64054dfc386b747e32479950df9f9d
parent8b0210d23367efecbf6e8ee9f19f372ff7d4fad3 (diff)
switch to rayon threadpool
-rw-r--r--crates/server/Cargo.toml2
-rw-r--r--crates/server/src/lib.rs2
-rw-r--r--crates/server/src/main_loop/mod.rs14
3 files changed, 10 insertions, 8 deletions
diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml
index cb96929c6..9aeea9a9b 100644
--- a/crates/server/Cargo.toml
+++ b/crates/server/Cargo.toml
@@ -4,6 +4,7 @@ version = "0.1.0"
4authors = ["Aleksey Kladov <[email protected]>"] 4authors = ["Aleksey Kladov <[email protected]>"]
5 5
6[dependencies] 6[dependencies]
7rayon = "1.0.2"
7relative-path = "0.3.7" 8relative-path = "0.3.7"
8failure = "0.1.2" 9failure = "0.1.2"
9serde_json = "1.0.24" 10serde_json = "1.0.24"
@@ -11,7 +12,6 @@ serde = "1.0.71"
11serde_derive = "1.0.71" 12serde_derive = "1.0.71"
12drop_bomb = "0.1.0" 13drop_bomb = "0.1.0"
13crossbeam-channel = "0.2.4" 14crossbeam-channel = "0.2.4"
14threadpool = "1.7.1"
15flexi_logger = "0.9.1" 15flexi_logger = "0.9.1"
16log = "0.4.3" 16log = "0.4.3"
17url_serde = "0.2.0" 17url_serde = "0.2.0"
diff --git a/crates/server/src/lib.rs b/crates/server/src/lib.rs
index d874ecf84..9e094af10 100644
--- a/crates/server/src/lib.rs
+++ b/crates/server/src/lib.rs
@@ -7,7 +7,7 @@ extern crate serde_json;
7extern crate languageserver_types; 7extern crate languageserver_types;
8#[macro_use] 8#[macro_use]
9extern crate crossbeam_channel; 9extern crate crossbeam_channel;
10extern crate threadpool; 10extern crate rayon;
11#[macro_use] 11#[macro_use]
12extern crate log; 12extern crate log;
13extern crate drop_bomb; 13extern crate drop_bomb;
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs
index 52e3b661d..52f2a8977 100644
--- a/crates/server/src/main_loop/mod.rs
+++ b/crates/server/src/main_loop/mod.rs
@@ -6,9 +6,9 @@ use std::{
6 collections::{HashMap}, 6 collections::{HashMap},
7}; 7};
8 8
9use threadpool::ThreadPool;
10use serde::{Serialize, de::DeserializeOwned}; 9use serde::{Serialize, de::DeserializeOwned};
11use crossbeam_channel::{unbounded, Sender, Receiver}; 10use crossbeam_channel::{unbounded, Sender, Receiver};
11use rayon::{self, ThreadPool};
12use languageserver_types::{NumberOrString}; 12use languageserver_types::{NumberOrString};
13use libanalysis::{FileId, JobHandle, JobToken, LibraryData}; 13use libanalysis::{FileId, JobHandle, JobToken, LibraryData};
14use gen_lsp_server::{ 14use gen_lsp_server::{
@@ -37,7 +37,9 @@ pub fn main_loop(
37 msg_receriver: &mut Receiver<RawMessage>, 37 msg_receriver: &mut Receiver<RawMessage>,
38 msg_sender: &mut Sender<RawMessage>, 38 msg_sender: &mut Sender<RawMessage>,
39) -> Result<()> { 39) -> Result<()> {
40 let pool = ThreadPool::new(4); 40 let pool = rayon::ThreadPoolBuilder::new()
41 .num_threads(4).build()
42 .unwrap();
41 let (task_sender, task_receiver) = unbounded::<Task>(); 43 let (task_sender, task_receiver) = unbounded::<Task>();
42 let (fs_sender, fs_receiver, fs_watcher) = vfs::roots_loader(); 44 let (fs_sender, fs_receiver, fs_watcher) = vfs::roots_loader();
43 let (ws_sender, ws_receiver, ws_watcher) = workspace_loader(); 45 let (ws_sender, ws_receiver, ws_watcher) = workspace_loader();
@@ -68,7 +70,7 @@ pub fn main_loop(
68 task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests)); 70 task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests));
69 info!("...tasks have finished"); 71 info!("...tasks have finished");
70 info!("joining threadpool..."); 72 info!("joining threadpool...");
71 pool.join(); 73 drop(pool);
72 info!("...threadpool has finished"); 74 info!("...threadpool has finished");
73 75
74 let fs_res = fs_watcher.stop(); 76 let fs_res = fs_watcher.stop();
@@ -136,7 +138,7 @@ fn main_loop_inner(
136 } else { 138 } else {
137 let files = state.events_to_files(events); 139 let files = state.events_to_files(events);
138 let sender = libdata_sender.clone(); 140 let sender = libdata_sender.clone();
139 pool.execute(move || { 141 pool.spawn(move || {
140 let start = ::std::time::Instant::now(); 142 let start = ::std::time::Instant::now();
141 info!("indexing {} ... ", root.display()); 143 info!("indexing {} ... ", root.display());
142 let data = LibraryData::prepare(files); 144 let data = LibraryData::prepare(files);
@@ -354,7 +356,7 @@ impl<'a> PoolDispatcher<'a> {
354 let (handle, token) = JobHandle::new(); 356 let (handle, token) = JobHandle::new();
355 let world = self.world.snapshot(); 357 let world = self.world.snapshot();
356 let sender = self.sender.clone(); 358 let sender = self.sender.clone();
357 self.pool.execute(move || { 359 self.pool.spawn(move || {
358 let resp = match f(world, params, token) { 360 let resp = match f(world, params, token) {
359 Ok(resp) => RawResponse::ok::<R>(id, &resp), 361 Ok(resp) => RawResponse::ok::<R>(id, &resp),
360 Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()), 362 Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()),
@@ -386,7 +388,7 @@ fn update_file_notifications_on_threadpool(
386 sender: Sender<Task>, 388 sender: Sender<Task>,
387 subscriptions: Vec<FileId>, 389 subscriptions: Vec<FileId>,
388) { 390) {
389 pool.execute(move || { 391 pool.spawn(move || {
390 for file_id in subscriptions { 392 for file_id in subscriptions {
391 match handlers::publish_diagnostics(world.clone(), file_id) { 393 match handlers::publish_diagnostics(world.clone(), file_id) {
392 Err(e) => { 394 Err(e) => {