Unverified Commit 8952a10e authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

refactor(turbopack): Remove `ReadRawVcFuture.turbo_task` (#75217)

### Why?

`core::ptr::drop_in_place` of `ReadRawVcFuture.turbo_task` is consuming too much time.
parent 2f0c80fb
...@@ -594,7 +594,10 @@ impl<B: Backend + 'static> TurboTasks<B> { ...@@ -594,7 +594,10 @@ impl<B: Backend + 'static> TurboTasks<B> {
// track a dependency // track a dependency
let raw_result = let raw_result =
read_task_output_untracked(self, task_id, ReadConsistency::Eventual).await?; read_task_output_untracked(self, task_id, ReadConsistency::Eventual).await?;
ReadVcFuture::<Completion>::from(raw_result.into_read_untracked_with_turbo_tasks(self)) turbo_tasks_future_scope(
self.pin(),
ReadVcFuture::<Completion>::from(raw_result.into_read_untracked_with_turbo_tasks(self)),
)
.await?; .await?;
Ok(rx.await?) Ok(rx.await?)
...@@ -1748,7 +1751,8 @@ pub async fn run_once<T: Send + 'static>( ...@@ -1748,7 +1751,8 @@ pub async fn run_once<T: Send + 'static>(
// INVALIDATION: A Once task will never invalidate, therefore we don't need to // INVALIDATION: A Once task will never invalidate, therefore we don't need to
// track a dependency // track a dependency
let raw_result = read_task_output_untracked(&*tt, task_id, ReadConsistency::Eventual).await?; let raw_result = read_task_output_untracked(&*tt, task_id, ReadConsistency::Eventual).await?;
ReadVcFuture::<Completion>::from(raw_result.into_read_untracked_with_turbo_tasks(&*tt)).await?; let raw_future = raw_result.into_read_untracked_with_turbo_tasks(&*tt);
turbo_tasks_future_scope(tt, ReadVcFuture::<Completion>::from(raw_future)).await?;
Ok(rx.await?) Ok(rx.await?)
} }
...@@ -1773,7 +1777,8 @@ pub async fn run_once_with_reason<T: Send + 'static>( ...@@ -1773,7 +1777,8 @@ pub async fn run_once_with_reason<T: Send + 'static>(
// INVALIDATION: A Once task will never invalidate, therefore we don't need to // INVALIDATION: A Once task will never invalidate, therefore we don't need to
// track a dependency // track a dependency
let raw_result = read_task_output_untracked(&*tt, task_id, ReadConsistency::Eventual).await?; let raw_result = read_task_output_untracked(&*tt, task_id, ReadConsistency::Eventual).await?;
ReadVcFuture::<Completion>::from(raw_result.into_read_untracked_with_turbo_tasks(&*tt)).await?; let raw_future = raw_result.into_read_untracked_with_turbo_tasks(&*tt);
turbo_tasks_future_scope(tt, ReadVcFuture::<Completion>::from(raw_future)).await?;
Ok(rx.await?) Ok(rx.await?)
} }
......
use std::{ use std::{fmt::Display, future::Future, pin::Pin, task::Poll};
fmt::{Debug, Display},
future::Future,
hash::Hash,
pin::Pin,
sync::Arc,
task::Poll,
};
use anyhow::Result; use anyhow::Result;
use auto_hash_map::AutoSet; use auto_hash_map::AutoSet;
...@@ -18,7 +11,7 @@ use crate::{ ...@@ -18,7 +11,7 @@ use crate::{
id::{ExecutionId, LocalCellId, LocalTaskId}, id::{ExecutionId, LocalCellId, LocalTaskId},
manager::{ manager::{
assert_execution_id, current_task, read_local_cell, read_local_output, read_task_cell, assert_execution_id, current_task, read_local_cell, read_local_output, read_task_cell,
read_task_output, TurboTasksApi, read_task_output, with_turbo_tasks, TurboTasksApi,
}, },
registry::{self, get_value_type}, registry::{self, get_value_type},
turbo_tasks, CollectiblesSource, ReadConsistency, TaskId, TraitTypeId, ValueType, ValueTypeId, turbo_tasks, CollectiblesSource, ReadConsistency, TaskId, TraitTypeId, ValueType, ValueTypeId,
...@@ -335,7 +328,6 @@ impl CollectiblesSource for RawVc { ...@@ -335,7 +328,6 @@ impl CollectiblesSource for RawVc {
} }
pub struct ReadRawVcFuture { pub struct ReadRawVcFuture {
turbo_tasks: Arc<dyn TurboTasksApi>,
consistency: ReadConsistency, consistency: ReadConsistency,
current: RawVc, current: RawVc,
untracked: bool, untracked: bool,
...@@ -344,9 +336,7 @@ pub struct ReadRawVcFuture { ...@@ -344,9 +336,7 @@ pub struct ReadRawVcFuture {
impl ReadRawVcFuture { impl ReadRawVcFuture {
pub(crate) fn new(vc: RawVc) -> Self { pub(crate) fn new(vc: RawVc) -> Self {
let tt = turbo_tasks();
ReadRawVcFuture { ReadRawVcFuture {
turbo_tasks: tt,
consistency: ReadConsistency::Eventual, consistency: ReadConsistency::Eventual,
current: vc, current: vc,
untracked: false, untracked: false,
...@@ -354,10 +344,8 @@ impl ReadRawVcFuture { ...@@ -354,10 +344,8 @@ impl ReadRawVcFuture {
} }
} }
fn new_untracked_with_turbo_tasks(vc: RawVc, turbo_tasks: &dyn TurboTasksApi) -> Self { fn new_untracked_with_turbo_tasks(vc: RawVc, _turbo_tasks: &dyn TurboTasksApi) -> Self {
let tt = turbo_tasks.pin();
ReadRawVcFuture { ReadRawVcFuture {
turbo_tasks: tt,
consistency: ReadConsistency::Eventual, consistency: ReadConsistency::Eventual,
current: vc, current: vc,
untracked: true, untracked: true,
...@@ -366,9 +354,7 @@ impl ReadRawVcFuture { ...@@ -366,9 +354,7 @@ impl ReadRawVcFuture {
} }
fn new_untracked(vc: RawVc) -> Self { fn new_untracked(vc: RawVc) -> Self {
let tt = turbo_tasks();
ReadRawVcFuture { ReadRawVcFuture {
turbo_tasks: tt,
consistency: ReadConsistency::Eventual, consistency: ReadConsistency::Eventual,
current: vc, current: vc,
untracked: true, untracked: true,
...@@ -377,9 +363,7 @@ impl ReadRawVcFuture { ...@@ -377,9 +363,7 @@ impl ReadRawVcFuture {
} }
fn new_strongly_consistent(vc: RawVc) -> Self { fn new_strongly_consistent(vc: RawVc) -> Self {
let tt = turbo_tasks();
ReadRawVcFuture { ReadRawVcFuture {
turbo_tasks: tt,
consistency: ReadConsistency::Strong, consistency: ReadConsistency::Strong,
current: vc, current: vc,
untracked: false, untracked: false,
...@@ -388,9 +372,7 @@ impl ReadRawVcFuture { ...@@ -388,9 +372,7 @@ impl ReadRawVcFuture {
} }
fn new_strongly_consistent_untracked(vc: RawVc) -> Self { fn new_strongly_consistent_untracked(vc: RawVc) -> Self {
let tt = turbo_tasks();
ReadRawVcFuture { ReadRawVcFuture {
turbo_tasks: tt,
consistency: ReadConsistency::Strong, consistency: ReadConsistency::Strong,
current: vc, current: vc,
untracked: true, untracked: true,
...@@ -403,7 +385,8 @@ impl Future for ReadRawVcFuture { ...@@ -403,7 +385,8 @@ impl Future for ReadRawVcFuture {
type Output = Result<TypedCellContent>; type Output = Result<TypedCellContent>;
fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
self.turbo_tasks.notify_scheduled_tasks(); with_turbo_tasks(|tt| {
tt.notify_scheduled_tasks();
// SAFETY: we are not moving this // SAFETY: we are not moving this
let this = unsafe { self.get_unchecked_mut() }; let this = unsafe { self.get_unchecked_mut() };
'outer: loop { 'outer: loop {
...@@ -418,17 +401,16 @@ impl Future for ReadRawVcFuture { ...@@ -418,17 +401,16 @@ impl Future for ReadRawVcFuture {
let mut listener = match this.current { let mut listener = match this.current {
RawVc::TaskOutput(task) => { RawVc::TaskOutput(task) => {
let read_result = if this.untracked { let read_result = if this.untracked {
this.turbo_tasks tt.try_read_task_output_untracked(task, this.consistency)
.try_read_task_output_untracked(task, this.consistency)
} else { } else {
this.turbo_tasks tt.try_read_task_output(task, this.consistency)
.try_read_task_output(task, this.consistency)
}; };
match read_result { match read_result {
Ok(Ok(vc)) => { Ok(Ok(vc)) => {
// We no longer need to read strongly consistent, as any Vc returned // We no longer need to read strongly consistent, as any Vc returned
// from the first task will be inside of the scope of the first task. So // from the first task will be inside of the scope of the first
// it's already strongly consistent. // task. So it's already strongly
// consistent.
this.consistency = ReadConsistency::Eventual; this.consistency = ReadConsistency::Eventual;
this.current = vc; this.current = vc;
continue 'outer; continue 'outer;
...@@ -439,9 +421,9 @@ impl Future for ReadRawVcFuture { ...@@ -439,9 +421,9 @@ impl Future for ReadRawVcFuture {
} }
RawVc::TaskCell(task, index) => { RawVc::TaskCell(task, index) => {
let read_result = if this.untracked { let read_result = if this.untracked {
this.turbo_tasks.try_read_task_cell_untracked(task, index) tt.try_read_task_cell_untracked(task, index)
} else { } else {
this.turbo_tasks.try_read_task_cell(task, index) tt.try_read_task_cell(task, index)
}; };
match read_result { match read_result {
Ok(Ok(content)) => { Ok(Ok(content)) => {
...@@ -454,17 +436,13 @@ impl Future for ReadRawVcFuture { ...@@ -454,17 +436,13 @@ impl Future for ReadRawVcFuture {
} }
RawVc::LocalOutput(task_id, local_output_id) => { RawVc::LocalOutput(task_id, local_output_id) => {
let read_result = if this.untracked { let read_result = if this.untracked {
this.turbo_tasks.try_read_local_output_untracked( tt.try_read_local_output_untracked(
task_id, task_id,
local_output_id, local_output_id,
this.consistency, this.consistency,
) )
} else { } else {
this.turbo_tasks.try_read_local_output( tt.try_read_local_output(task_id, local_output_id, this.consistency)
task_id,
local_output_id,
this.consistency,
)
}; };
match read_result { match read_result {
Ok(Ok(vc)) => { Ok(Ok(vc)) => {
...@@ -477,7 +455,9 @@ impl Future for ReadRawVcFuture { ...@@ -477,7 +455,9 @@ impl Future for ReadRawVcFuture {
} }
} }
RawVc::LocalCell(execution_id, local_cell_id) => { RawVc::LocalCell(execution_id, local_cell_id) => {
return Poll::Ready(Ok(read_local_cell(execution_id, local_cell_id).into())); return Poll::Ready(
Ok(read_local_cell(execution_id, local_cell_id).into()),
);
} }
}; };
// SAFETY: listener is from previous pinned this // SAFETY: listener is from previous pinned this
...@@ -489,6 +469,7 @@ impl Future for ReadRawVcFuture { ...@@ -489,6 +469,7 @@ impl Future for ReadRawVcFuture {
} }
}; };
} }
})
} }
} }
......
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