From 360074effbab6c16af40f87095911856ce9658d7 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 28 Oct 2025 21:21:49 +0100 Subject: [PATCH] rope: Prevent stack overflows by bumping rayon stack sizes (#41397) Thread stacks in rust by default have 2 megabytes of stack which for sumtrees (or ropes in this case) can easily be exceeded depending on the workload. Release Notes: - Fixed stack overflows when constructing large ropes --- crates/cli/src/main.rs | 1 + crates/remote_server/src/unix.rs | 1 + crates/rope/src/rope.rs | 8 ++++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index bb2f2effbbf8ff0d8995b8607c1ce2ddff66ac0c..a16f5a3bab9849ee93abac4e2eccb602698b65de 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -358,6 +358,7 @@ fn main() -> Result<()> { rayon::ThreadPoolBuilder::new() .num_threads(4) + .stack_size(10 * 1024 * 1024) .thread_name(|ix| format!("RayonWorker{}", ix)) .build_global() .unwrap(); diff --git a/crates/remote_server/src/unix.rs b/crates/remote_server/src/unix.rs index 1a7dc8c9621354a385a65567960a6215f680528c..d11fb4031e6386e66090b1cfb106dd5d0a7dac05 100644 --- a/crates/remote_server/src/unix.rs +++ b/crates/remote_server/src/unix.rs @@ -372,6 +372,7 @@ pub fn execute_run( rayon::ThreadPoolBuilder::new() .num_threads(4) + .stack_size(10 * 1024 * 1024) .thread_name(|ix| format!("RayonWorker{}", ix)) .build_global() .unwrap(); diff --git a/crates/rope/src/rope.rs b/crates/rope/src/rope.rs index c61346e0376bf8c97cd2af3a454f20953f6eaed9..394e6ef0ca589d19ffcf7cf07a92bcd15c8e4a18 100644 --- a/crates/rope/src/rope.rs +++ b/crates/rope/src/rope.rs @@ -191,9 +191,9 @@ impl Rope { (), ); - #[cfg(not(test))] + #[cfg(all(test, not(rust_analyzer)))] const NUM_CHUNKS: usize = 16; - #[cfg(test)] + #[cfg(not(all(test, not(rust_analyzer))))] const NUM_CHUNKS: usize = 4; // We accommodate for NUM_CHUNKS chunks of size MAX_BASE @@ -248,9 +248,9 @@ impl Rope { text = remainder; } - #[cfg(test)] + #[cfg(all(test, not(rust_analyzer)))] const PARALLEL_THRESHOLD: usize = 4; - #[cfg(not(test))] + #[cfg(not(all(test, not(rust_analyzer))))] const PARALLEL_THRESHOLD: usize = 4 * (2 * sum_tree::TREE_BASE); if new_chunks.len() >= PARALLEL_THRESHOLD {