Unverified Commit c16109f4 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: speedup module merging (#85043)

preallocate hashmaps
parent 3f09e569
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
use crate::{ use crate::{
scope::scope_and_block, scope::scope_and_block,
util::{good_chunk_size, into_chunks}, util::{Chunk, good_chunk_size, into_chunks},
}; };
struct Chunked { struct Chunked {
...@@ -231,6 +231,32 @@ where ...@@ -231,6 +231,32 @@ where
.collect() .collect()
} }
pub fn map_collect_chunked_owned<'l, Item, PerItemResult, Result>(
items: Vec<Item>,
f: impl Fn(Chunk<Item>) -> PerItemResult + Send + Sync,
) -> Result
where
Item: Send + Sync,
PerItemResult: Send + Sync + 'l,
Result: FromIterator<PerItemResult>,
{
let Some(Chunked {
chunk_size,
chunk_count,
}) = get_chunked(items.len())
else {
let len = items.len();
return Result::from_iter(into_chunks(items, len).map(f));
};
let f = &f;
scope_and_block(chunk_count, |scope| {
for chunk in into_chunks(items, chunk_size) {
scope.spawn(move || f(chunk))
}
})
.collect()
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::{ use std::{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment