Skip to content

Commit e5fee81

Browse files
committed
tokio + rayon
1 parent dcd5ed0 commit e5fee81

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

turbopack/crates/turbo-tasks-backend/src/backend/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
18871887
}
18881888

18891889
let this = self.clone();
1890-
let snapshot = turbo_tasks::spawn_blocking(move || this.snapshot()).await;
1890+
let snapshot = turbo_tasks::spawn_blocking_rayon(move || this.snapshot()).await;
18911891
if let Some((snapshot_start, new_data)) = snapshot {
18921892
last_snapshot = snapshot_start;
18931893
if new_data {

turbopack/crates/turbo-tasks-fs/src/retry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ where
2929
{
3030
let path = path.as_ref().to_owned();
3131

32-
turbo_tasks::spawn_blocking(move || {
32+
turbo_tasks::spawn_blocking_tokio(move || {
3333
let mut attempt = 1;
3434

3535
loop {

turbopack/crates/turbo-tasks/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ pub use manager::{
109109
CurrentCellRef, ReadConsistency, TaskPersistence, TurboTasks, TurboTasksApi,
110110
TurboTasksBackendApi, TurboTasksBackendApiExt, TurboTasksCallApi, Unused, UpdateInfo,
111111
dynamic_call, emit, mark_finished, mark_root, mark_session_dependent, mark_stateful,
112-
prevent_gc, run_once, run_once_with_reason, spawn_blocking, spawn_thread, trait_call,
113-
turbo_tasks, turbo_tasks_scope,
112+
prevent_gc, run_once, run_once_with_reason, spawn_blocking_rayon, spawn_blocking_tokio,
113+
spawn_thread, trait_call, turbo_tasks, turbo_tasks_scope,
114114
};
115115
pub use output::OutputContent;
116116
pub use raw_vc::{CellId, RawVc, ReadRawVcFuture, ResolveTypeError};

turbopack/crates/turbo-tasks/src/manager.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,9 @@ pub fn emit<T: VcValueTrait + ?Sized>(collectible: ResolvedVc<T>) {
17841784
})
17851785
}
17861786

1787-
pub async fn spawn_blocking<T: Send + 'static>(func: impl FnOnce() -> T + Send + 'static) -> T {
1787+
pub async fn spawn_blocking_tokio<T: Send + 'static>(
1788+
func: impl FnOnce() -> T + Send + 'static,
1789+
) -> T {
17881790
let turbo_tasks = turbo_tasks();
17891791
let span = Span::current();
17901792
let (result, duration, alloc_info) = tokio::task::spawn_blocking(|| {
@@ -1801,6 +1803,27 @@ pub async fn spawn_blocking<T: Send + 'static>(func: impl FnOnce() -> T + Send +
18011803
result
18021804
}
18031805

1806+
pub async fn spawn_blocking_rayon<T: Send + 'static>(
1807+
func: impl FnOnce() -> T + Send + 'static,
1808+
) -> T {
1809+
let (tx, rx) = tokio::sync::oneshot::channel();
1810+
1811+
let turbo_tasks = turbo_tasks();
1812+
let span = Span::current();
1813+
rayon::spawn(|| {
1814+
let _guard = span.entered();
1815+
let start = Instant::now();
1816+
let start_allocations = TurboMalloc::allocation_counters();
1817+
let r = turbo_tasks_scope(turbo_tasks, func);
1818+
let _ = tx.send((r, start.elapsed(), start_allocations.until_now()));
1819+
});
1820+
1821+
let (result, duration, alloc_info) = rx.await.unwrap();
1822+
capture_future::add_duration(duration);
1823+
capture_future::add_allocation_info(alloc_info);
1824+
result
1825+
}
1826+
18041827
pub fn spawn_thread(func: impl FnOnce() + Send + 'static) {
18051828
let handle = Handle::current();
18061829
let span = info_span!("thread").or_current();

0 commit comments

Comments
 (0)