Unverified Commit 6dc3a5a7 authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

Don't track modifications to transient data stored in tasks (#95133)

Many fields in TaskStorage store a mix of transient and persistent data.
When we serialize we leverage the `filter_transient` tag (and the
`IsTransient` trait) to avoid persisting it, however, when mutations
occur we are still marking the tasks as `modified` even when we are only
modifying transient data.

This leads to unnecessary persistence cycles.

The solution is simply to not call `track_modification` when the
modification is about transient data items.

For most fields this is handled in the macro accessors, but for
`cell_data` this is managed via some new 'handwritten' mutators
implemented on `TaskGuard`. This is desirable to decrease the number of
times we do registry lookups since most callers who modify the cell_data
already have the ValueType in hand
parent 668cd3a4
......@@ -1344,7 +1344,7 @@ pub async fn project_write_all_entrypoints_to_disk(
let phase_build_paths = if has_deferred_entrypoints {
Some(
tt.run(async move {
#[turbo_tasks::value]
#[turbo_tasks::value(serialization = "skip")]
struct DeferredEntrypointInfo(ReadRef<Entrypoints>, ReadRef<Vec<RcStr>>);
#[turbo_tasks::function(operation, root)]
......
......@@ -842,7 +842,7 @@ impl TurboTasksBackend {
};
let content = if final_read_hint {
task.remove_cell_data(&cell)
task.remove_cell_data(&cell, &get_value_type(cell.type_id()).persistence)
} else {
task.get_cell_data(&cell).cloned()
};
......@@ -2778,7 +2778,9 @@ impl TurboTasksBackend {
.collect();
removed_cell_data.reserve_exact(to_remove.len());
for cell in to_remove {
if let Some(data) = task.remove_cell_data(&cell) {
if let Some(data) =
task.remove_cell_data(&cell, &get_value_type(cell.type_id()).persistence)
{
removed_cell_data.push(data);
}
}
......
......@@ -188,7 +188,7 @@ impl UpdateCellOperation {
// tasks and after that set the new cell content. When the cell content is unset,
// readers will wait for it to be set via InProgressCell.
let old_content = task.remove_cell_data(&cell);
let old_content = task.remove_cell_data(&cell, &value_type.persistence);
// Update cell_data_hash before dropping the task lock
if matches!(value_type.persistence, ValueTypePersistence::HashOnly) {
......@@ -225,9 +225,9 @@ impl UpdateCellOperation {
// So we can just update the cell content.
let old_content = if let Some(new_content) = content {
task.insert_cell_data(cell, new_content)
task.insert_cell_data(cell, new_content, &value_type.persistence)
} else {
task.remove_cell_data(&cell)
task.remove_cell_data(&cell, &value_type.persistence)
};
// Update cell_data_hash for hash-only cells.
......@@ -355,7 +355,11 @@ impl Operation for UpdateCellOperation {
let mut task = ctx.task(task, TaskDataCategory::Data);
if let Some(content) = content {
task.add_cell_data(cell, content.into_untyped());
// This arm only carries the CellId, so resolve the cell's
// persistence here (one lookup per final change, not on the
// inner hot path) to decide whether the write tracks.
let persistence = &registry::get_value_type(cell.type_id()).persistence;
task.add_cell_data(cell, content.into_untyped(), persistence);
}
let in_progress_cell = task.remove_in_progress_cells(&cell);
......
......@@ -327,6 +327,7 @@ struct TaskStorageSchema {
category = "data",
shrink_on_completion,
custom_drop_partial,
custom_mutators,
as_type = "AutoMap<CellId, SharedReference, 1>"
)]
cell_data: CellData,
......
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