这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/turbo-tasks-memory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ print_scope_updates = []
print_task_invalidation = []
inline_add_to_scope = []
inline_remove_from_scope = []
default = []
lazy_remove_children = []
default = ["lazy_remove_children"]

[[bench]]
name = "mod"
Expand Down
32 changes: 31 additions & 1 deletion crates/turbo-tasks-memory/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ enum TaskStateType {
event: Event,
count_as_finished: bool,
/// Children that need to be disconnected once leaving this state
#[cfg(feature = "lazy_remove_children")]
outdated_children: TaskIdSet,
outdated_collectibles: MaybeCollectibles,
},
Expand Down Expand Up @@ -680,6 +681,8 @@ impl Task {
let dependencies;
let (future, span) = {
let mut state = self.full_state_mut();
#[cfg(not(feature = "lazy_remove_children"))]
let remove_job;
match state.state_type {
Done { .. } | InProgress { .. } | InProgressDirty { .. } => {
// should not start in this state
Expand All @@ -693,9 +696,16 @@ impl Task {
dependencies = take(outdated_dependencies);
let outdated_children = take(&mut state.children);
let outdated_collectibles = take(&mut state.collectibles);
#[cfg(not(feature = "lazy_remove_children"))]
{
remove_job = state
.aggregation_leaf
.remove_children_job(&aggregation_context, outdated_children);
}
state.state_type = InProgress {
event,
count_as_finished: false,
#[cfg(feature = "lazy_remove_children")]
outdated_children,
outdated_collectibles,
};
Expand All @@ -709,7 +719,13 @@ impl Task {
)
}
};
self.make_execution_future(state, backend, turbo_tasks)
let result = self.make_execution_future(state, backend, turbo_tasks);
#[cfg(not(feature = "lazy_remove_children"))]
{
remove_job();
}
#[allow(clippy::let_and_return)]
result
};
aggregation_context.apply_queued_updates();
self.clear_dependencies(dependencies, backend, turbo_tasks);
Expand Down Expand Up @@ -816,6 +832,7 @@ impl Task {
};
let TaskStateType::InProgress {
ref mut count_as_finished,
#[cfg(feature = "lazy_remove_children")]
ref mut outdated_children,
ref mut outdated_collectibles,
..
Expand All @@ -829,6 +846,7 @@ impl Task {
*count_as_finished = true;
let mut aggregation_context = TaskAggregationContext::new(turbo_tasks, backend);
{
#[cfg(feature = "lazy_remove_children")]
let outdated_children = take(outdated_children);
let outdated_collectibles = outdated_collectibles.take_collectibles();

Expand All @@ -846,6 +864,7 @@ impl Task {
let change_job = state
.aggregation_leaf
.change_job(&aggregation_context, change);
#[cfg(feature = "lazy_remove_children")]
let remove_job = if outdated_children.is_empty() {
None
} else {
Expand All @@ -857,6 +876,7 @@ impl Task {
};
drop(state);
change_job();
#[cfg(feature = "lazy_remove_children")]
if let Some(job) = remove_job {
job();
}
Expand Down Expand Up @@ -926,6 +946,7 @@ impl Task {
let mut schedule_task = false;
{
let mut change_job = None;
#[cfg(feature = "lazy_remove_children")]
let mut remove_job = None;
let mut dependencies = DEPENDENCIES_TO_TRACK.with(|deps| deps.take());
{
Expand All @@ -938,10 +959,12 @@ impl Task {
InProgress {
ref mut event,
count_as_finished,
#[cfg(feature = "lazy_remove_children")]
ref mut outdated_children,
ref mut outdated_collectibles,
} => {
let event = event.take();
#[cfg(feature = "lazy_remove_children")]
let outdated_children = take(outdated_children);
let outdated_collectibles = outdated_collectibles.take_collectibles();
let mut dependencies = take(&mut dependencies);
Expand Down Expand Up @@ -972,6 +995,7 @@ impl Task {
.change_job(&aggregation_context, change),
);
}
#[cfg(feature = "lazy_remove_children")]
if !outdated_children.is_empty() {
remove_job = Some(
state
Expand Down Expand Up @@ -1003,6 +1027,7 @@ impl Task {
if let Some(job) = change_job {
job();
}
#[cfg(feature = "lazy_remove_children")]
if let Some(job) = remove_job {
job();
}
Expand Down Expand Up @@ -1149,10 +1174,12 @@ impl Task {
InProgress {
ref mut event,
count_as_finished,
#[cfg(feature = "lazy_remove_children")]
ref mut outdated_children,
ref mut outdated_collectibles,
} => {
let event = event.take();
#[cfg(feature = "lazy_remove_children")]
let outdated_children = take(outdated_children);
let outdated_collectibles = outdated_collectibles.take_collectibles();
let change = if count_as_finished {
Expand Down Expand Up @@ -1182,6 +1209,7 @@ impl Task {
.aggregation_leaf
.change_job(&aggregation_context, change)
});
#[cfg(feature = "lazy_remove_children")]
let remove_job = state
.aggregation_leaf
.remove_children_job(&aggregation_context, outdated_children);
Expand All @@ -1190,6 +1218,7 @@ impl Task {
if let Some(job) = change_job {
job();
}
#[cfg(feature = "lazy_remove_children")]
remove_job();
}
}
Expand Down Expand Up @@ -1461,6 +1490,7 @@ impl Task {
let TaskGuard { guard, .. } = guard;
let mut state = TaskMetaStateWriteGuard::full_from(guard.into_inner(), self);
if state.children.insert(child_id) {
#[cfg(feature = "lazy_remove_children")]
if let TaskStateType::InProgress {
outdated_children, ..
} = &mut state.state_type
Expand Down
40 changes: 25 additions & 15 deletions crates/turbo-tasks-memory/src/task/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ impl<'l> AggregationItemLock for TaskGuard<'l> {
fn number_of_children(&self) -> usize {
match self.guard {
TaskMetaStateWriteGuard::Full(ref guard) => match &guard.state_type {
#[cfg(feature = "lazy_remove_children")]
TaskStateType::InProgress {
outdated_children, ..
} => guard.children.len() + outdated_children.len(),
Expand All @@ -428,21 +429,30 @@ impl<'l> AggregationItemLock for TaskGuard<'l> {
fn children(&self) -> Self::ChildrenIter<'_> {
match self.guard {
TaskMetaStateWriteGuard::Full(ref guard) => {
let outdated_children = match &guard.state_type {
TaskStateType::InProgress {
outdated_children, ..
} => Some(outdated_children.iter().map(Cow::Borrowed)),
_ => None,
};
Some(
guard
.children
.iter()
.map(Cow::Borrowed)
.chain(outdated_children.into_iter().flatten()),
)
.into_iter()
.flatten()
#[cfg(feature = "lazy_remove_children")]
{
let outdated_children = match &guard.state_type {
TaskStateType::InProgress {
outdated_children, ..
} => Some(outdated_children.iter().map(Cow::Borrowed)),
_ => None,
};
Some(
guard
.children
.iter()
.map(Cow::Borrowed)
.chain(outdated_children.into_iter().flatten()),
)
.into_iter()
.flatten()
}
#[cfg(not(feature = "lazy_remove_children"))]
{
Some(guard.children.iter().map(Cow::Borrowed))
.into_iter()
.flatten()
}
}
TaskMetaStateWriteGuard::Partial(_) | TaskMetaStateWriteGuard::Unloaded(_) => {
None.into_iter().flatten()
Expand Down