From dc366165b8cd0f8c43cfe7017cb37f0a16887d6d Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 14 Jul 2026 20:48:18 +0200 Subject: chore: simplify runtime, parser, types, and SIMD internals Signed-off-by: Henry --- crates/parser/src/parallel.rs | 100 ++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 53 deletions(-) (limited to 'crates/parser/src/parallel.rs') diff --git a/crates/parser/src/parallel.rs b/crates/parser/src/parallel.rs index 4400053..8833970 100644 --- a/crates/parser/src/parallel.rs +++ b/crates/parser/src/parallel.rs @@ -94,10 +94,6 @@ pub(crate) fn process_pending( imported_func_count: usize, imported_memory_count: u32, ) -> Result> { - if pending.is_empty() { - return Ok(Vec::new()); - } - let (small_jobs, large_jobs): (Vec<_>, Vec<_>) = pending.into_iter().partition(|job| !should_parallelize_function(body_len(&job.body))); @@ -106,11 +102,6 @@ pub(crate) fn process_pending( .map(|job| process_function_job(job, options, func_types, imported_func_count, imported_memory_count)) .collect::>>()?; - if large_jobs.is_empty() { - codes.sort_by_key(|(ordinal, _)| *ordinal); - return Ok(codes.into_iter().map(|(_, code)| code).collect()); - } - let num_workers = worker_count(options, large_jobs.len()); if num_workers == 1 { codes.extend( @@ -119,54 +110,57 @@ pub(crate) fn process_pending( .map(|job| process_function_job(job, options, func_types, imported_func_count, imported_memory_count)) .collect::>>()?, ); - codes.sort_by_key(|(ordinal, _)| *ordinal); - return Ok(codes.into_iter().map(|(_, code)| code).collect()); - } - - let chunk_size = large_jobs.len().div_ceil(num_workers); - let chunks = { - let mut chunks = Vec::with_capacity(num_workers); - let mut iter = large_jobs.into_iter(); - while let Some(first) = iter.next() { - let mut chunk = alloc::vec![first]; - for _ in 1..chunk_size { - match iter.next() { - Some(job) => chunk.push(job), - None => break, + } else { + let chunk_size = large_jobs.len().div_ceil(num_workers); + let chunks = { + let mut chunks = Vec::with_capacity(num_workers); + let mut iter = large_jobs.into_iter(); + while let Some(first) = iter.next() { + let mut chunk = alloc::vec![first]; + for _ in 1..chunk_size { + match iter.next() { + Some(job) => chunk.push(job), + None => break, + } } + chunks.push(chunk); } - chunks.push(chunk); - } - chunks - }; + chunks + }; - let results: Vec> = std::thread::scope(|s| { - let handles: Vec<_> = chunks - .into_iter() - .map(|chunk| { - s.spawn(move || { - chunk - .into_iter() - .map(|job| { - process_function_job(job, options, func_types, imported_func_count, imported_memory_count) - }) - .collect::>() + let results: Vec> = std::thread::scope(|s| { + let handles: Vec<_> = chunks + .into_iter() + .map(|chunk| { + s.spawn(move || { + chunk + .into_iter() + .map(|job| { + process_function_job( + job, + options, + func_types, + imported_func_count, + imported_memory_count, + ) + }) + .collect::>() + }) }) - }) - .collect(); - - handles - .into_iter() - .flat_map(|handle| match handle.join() { - Ok(results) => results, - Err(_) => alloc::vec![Err(ParseError::Other("worker thread panicked".into()))], - }) - .collect() - }); - - for result in results { - let (ordinal, code) = result?; - codes.push((ordinal, code)); + .collect(); + + handles + .into_iter() + .flat_map(|handle| match handle.join() { + Ok(results) => results, + Err(_) => alloc::vec![Err(ParseError::Other("worker thread panicked".into()))], + }) + .collect() + }); + + for result in results { + codes.push(result?); + } } codes.sort_by_key(|(ordinal, _)| *ordinal); -- cgit v1.3.1