switch threadpool back from rayon to threadpool

rayon does not replenish the pool when the thread panics, but we must
be reselient to bugs.
This commit is contained in:
Aleksey Kladov 2018-12-09 13:13:36 +03:00
parent 904438e993
commit 13100da7a2
3 changed files with 17 additions and 9 deletions

10
Cargo.lock generated
View File

@ -697,6 +697,7 @@ dependencies = [
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"test_utils 0.1.0",
"text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1103,6 +1104,14 @@ dependencies = [
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "threadpool"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "time"
version = "0.1.40"
@ -1414,6 +1423,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8009d7bdbd896a7e09b595f8f9325a19047fc708653e60d0895202b82135048f"
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865"
"checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b"
"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
"checksum ucd-trie 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "71a9c5b1fe77426cf144cc30e49e955270f5086e31a6441dfa8b32efc09b9d77"

View File

@ -6,6 +6,7 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
[dependencies]
rayon = "1.0.2"
threadpool = "1.7.1"
relative-path = "0.4.0"
failure = "0.1.2"
failure_derive = "0.1.2"

View File

@ -9,7 +9,8 @@ use gen_lsp_server::{
};
use languageserver_types::NumberOrString;
use ra_analysis::{Canceled, FileId, LibraryData};
use rayon::{self, ThreadPool};
use rayon;
use threadpool::ThreadPool;
use rustc_hash::FxHashSet;
use serde::{de::DeserializeOwned, Serialize};
use failure::{format_err, bail};
@ -54,11 +55,7 @@ pub fn main_loop(
msg_receiver: &Receiver<RawMessage>,
msg_sender: &Sender<RawMessage>,
) -> Result<()> {
let pool = rayon::ThreadPoolBuilder::new()
.num_threads(4)
.panic_handler(|_| log::error!("thread panicked :("))
.build()
.unwrap();
let pool = ThreadPool::new(8);
let (task_sender, task_receiver) = unbounded::<Task>();
let (fs_worker, fs_watcher) = vfs::roots_loader();
let (ws_worker, ws_watcher) = workspace_loader();
@ -155,7 +152,7 @@ fn main_loop_inner(
} else {
let (files, resolver) = state.events_to_files(events);
let sender = libdata_sender.clone();
pool.spawn(move || {
pool.execute(move || {
let start = ::std::time::Instant::now();
log::info!("indexing {} ... ", root.display());
let data = LibraryData::prepare(files, resolver);
@ -402,7 +399,7 @@ impl<'a> PoolDispatcher<'a> {
Ok((id, params)) => {
let world = self.world.snapshot();
let sender = self.sender.clone();
self.pool.spawn(move || {
self.pool.execute(move || {
let resp = match f(world, params) {
Ok(resp) => RawResponse::ok::<R>(id, &resp),
Err(e) => match e.downcast::<LspError>() {
@ -452,7 +449,7 @@ fn update_file_notifications_on_threadpool(
sender: Sender<Task>,
subscriptions: Vec<FileId>,
) {
pool.spawn(move || {
pool.execute(move || {
for file_id in subscriptions {
match handlers::publish_diagnostics(&world, file_id) {
Err(e) => {