switch to rayon threadpool

This commit is contained in:
Aleksey Kladov 2018-09-04 20:43:37 +03:00
parent 8b0210d233
commit f87771092c
3 changed files with 10 additions and 8 deletions

View file

@ -4,6 +4,7 @@ version = "0.1.0"
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
[dependencies]
rayon = "1.0.2"
relative-path = "0.3.7"
failure = "0.1.2"
serde_json = "1.0.24"
@ -11,7 +12,6 @@ serde = "1.0.71"
serde_derive = "1.0.71"
drop_bomb = "0.1.0"
crossbeam-channel = "0.2.4"
threadpool = "1.7.1"
flexi_logger = "0.9.1"
log = "0.4.3"
url_serde = "0.2.0"

View file

@ -7,7 +7,7 @@ extern crate serde_json;
extern crate languageserver_types;
#[macro_use]
extern crate crossbeam_channel;
extern crate threadpool;
extern crate rayon;
#[macro_use]
extern crate log;
extern crate drop_bomb;

View file

@ -6,9 +6,9 @@ use std::{
collections::{HashMap},
};
use threadpool::ThreadPool;
use serde::{Serialize, de::DeserializeOwned};
use crossbeam_channel::{unbounded, Sender, Receiver};
use rayon::{self, ThreadPool};
use languageserver_types::{NumberOrString};
use libanalysis::{FileId, JobHandle, JobToken, LibraryData};
use gen_lsp_server::{
@ -37,7 +37,9 @@ pub fn main_loop(
msg_receriver: &mut Receiver<RawMessage>,
msg_sender: &mut Sender<RawMessage>,
) -> Result<()> {
let pool = ThreadPool::new(4);
let pool = rayon::ThreadPoolBuilder::new()
.num_threads(4).build()
.unwrap();
let (task_sender, task_receiver) = unbounded::<Task>();
let (fs_sender, fs_receiver, fs_watcher) = vfs::roots_loader();
let (ws_sender, ws_receiver, ws_watcher) = workspace_loader();
@ -68,7 +70,7 @@ pub fn main_loop(
task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests));
info!("...tasks have finished");
info!("joining threadpool...");
pool.join();
drop(pool);
info!("...threadpool has finished");
let fs_res = fs_watcher.stop();
@ -136,7 +138,7 @@ fn main_loop_inner(
} else {
let files = state.events_to_files(events);
let sender = libdata_sender.clone();
pool.execute(move || {
pool.spawn(move || {
let start = ::std::time::Instant::now();
info!("indexing {} ... ", root.display());
let data = LibraryData::prepare(files);
@ -354,7 +356,7 @@ impl<'a> PoolDispatcher<'a> {
let (handle, token) = JobHandle::new();
let world = self.world.snapshot();
let sender = self.sender.clone();
self.pool.execute(move || {
self.pool.spawn(move || {
let resp = match f(world, params, token) {
Ok(resp) => RawResponse::ok::<R>(id, &resp),
Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()),
@ -386,7 +388,7 @@ fn update_file_notifications_on_threadpool(
sender: Sender<Task>,
subscriptions: Vec<FileId>,
) {
pool.execute(move || {
pool.spawn(move || {
for file_id in subscriptions {
match handlers::publish_diagnostics(world.clone(), file_id) {
Err(e) => {