Add numThreads in config to avoid spawning lots of threads every time
This commit is contained in:
parent
6e8a54d0f6
commit
7d466570f4
@ -403,6 +403,9 @@ config_data! {
|
||||
/// Whether to show `can't find Cargo.toml` error message.
|
||||
notifications_cargoTomlNotFound: bool = "true",
|
||||
|
||||
/// How many worker threads in the main loop. The default `null` means to pick automatically.
|
||||
numThreads: Option<usize> = "null",
|
||||
|
||||
/// Expand attribute macros. Requires `#rust-analyzer.procMacro.enable#` to be set.
|
||||
procMacro_attributes_enable: bool = "true",
|
||||
/// Enable support for procedural macros, implies `#rust-analyzer.cargo.buildScripts.enable#`.
|
||||
@ -1454,6 +1457,10 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main_loop_num_threads(&self) -> usize {
|
||||
self.data.numThreads.unwrap_or(num_cpus::get_physical().try_into().unwrap_or(1))
|
||||
}
|
||||
|
||||
pub fn typing_autoclose_angle(&self) -> bool {
|
||||
self.data.typing_autoClosingAngleBrackets_enable
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ impl GlobalState {
|
||||
|
||||
let task_pool = {
|
||||
let (sender, receiver) = unbounded();
|
||||
let handle = TaskPool::new(sender);
|
||||
let handle = TaskPool::new_with_threads(sender, config.main_loop_num_threads());
|
||||
Handle { handle, receiver }
|
||||
};
|
||||
|
||||
|
@ -8,12 +8,13 @@ pub(crate) struct TaskPool<T> {
|
||||
}
|
||||
|
||||
impl<T> TaskPool<T> {
|
||||
pub(crate) fn new(sender: Sender<T>) -> TaskPool<T> {
|
||||
pub(crate) fn new_with_threads(sender: Sender<T>, threads: usize) -> TaskPool<T> {
|
||||
const STACK_SIZE: usize = 8 * 1024 * 1024;
|
||||
|
||||
let inner = threadpool::Builder::new()
|
||||
.thread_name("Worker".into())
|
||||
.thread_stack_size(STACK_SIZE)
|
||||
.num_threads(threads)
|
||||
.build();
|
||||
TaskPool { sender, inner }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user