Skip to content

Commit 0e1841a

Browse files
committed
use SharedReference to reduce size
1 parent 543a7ff commit 0e1841a

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,6 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
823823
let content = if final_read_hint {
824824
task.remove_cell_data(is_transient_cell, cell)
825825
} else if let Some(content) = task.get_cell_data(is_transient_cell, cell) {
826-
let content = content.clone();
827826
Some(content)
828827
} else {
829828
None
@@ -2544,7 +2543,8 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
25442543
let mut ctx = self.execute_context(turbo_tasks);
25452544
let task = ctx.task(task_id, TaskDataCategory::Data);
25462545
if let Some(content) = task.get_cell_data(options.is_transient_cell, cell) {
2547-
Ok(CellContent(Some(content.reference.clone())).into_typed(cell.type_id))
2546+
debug_assert!(content.type_id == cell.type_id, "Cell type ID mismatch");
2547+
Ok(CellContent(Some(content.reference)).into_typed(cell.type_id))
25482548
} else {
25492549
Ok(CellContent(None).into_typed(cell.type_id))
25502550
}

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,20 +475,23 @@ pub trait TaskGuard: Debug {
475475
cell: CellId,
476476
) -> Option<TypedSharedReference> {
477477
if is_transient_cell {
478-
remove!(self, TransientCellData { cell })
478+
remove!(self, TransientCellData { cell }).map(|sr| sr.into_typed(cell.type_id))
479479
} else {
480480
remove!(self, CellData { cell })
481481
}
482482
}
483-
fn get_cell_data(
484-
&self,
485-
is_transient_cell: bool,
486-
cell: CellId,
487-
) -> Option<&TypedSharedReference> {
483+
fn get_cell_data(&self, is_transient_cell: bool, cell: CellId) -> Option<TypedSharedReference> {
484+
if is_transient_cell {
485+
get!(self, TransientCellData { cell }).map(|sr| sr.clone().into_typed(cell.type_id))
486+
} else {
487+
get!(self, CellData { cell }).cloned()
488+
}
489+
}
490+
fn has_cell_data(&self, is_transient_cell: bool, cell: CellId) -> bool {
488491
if is_transient_cell {
489-
get!(self, TransientCellData { cell })
492+
self.has_key(&CachedDataItemKey::TransientCellData { cell })
490493
} else {
491-
get!(self, CellData { cell })
494+
self.has_key(&CachedDataItemKey::CellData { cell })
492495
}
493496
}
494497
}

turbopack/crates/turbo-tasks-backend/src/backend/operation/update_cell.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,17 @@ impl UpdateCellOperation {
6767
let assume_unchanged =
6868
!ctx.should_track_dependencies() || !task.has_key(&CachedDataItemKey::Dirty {});
6969

70-
let old_content = task.get_cell_data(is_transient_cell, cell);
71-
7270
if assume_unchanged {
73-
if old_content.is_some() {
71+
let has_old_content = task.has_cell_data(is_transient_cell, cell);
72+
if has_old_content {
7473
// Never update cells when recomputing if they already have a value.
7574
// It's not expected that content changes during recomputation.
7675

7776
// Check if this assumption holds.
7877
#[cfg(feature = "verify_determinism")]
7978
if !is_stateful
8079
&& matches!(verification_mode, VerificationMode::EqualityCheck)
81-
&& content.as_ref() != old_content
80+
&& content != task.get_cell_data(is_transient_cell, cell)
8281
{
8382
let task_description = ctx.get_task_description(task_id);
8483
let cell_type = turbo_tasks::registry::get_value_type(cell.type_id).global_name;

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use rustc_hash::FxHashSet;
22
use serde::{Deserialize, Serialize};
33
use turbo_tasks::{
4-
CellId, KeyValuePair, TaskExecutionReason, TaskId, TraitTypeId, TypedSharedReference,
5-
ValueTypeId,
4+
CellId, KeyValuePair, SharedReference, TaskExecutionReason, TaskId, TraitTypeId,
5+
TypedSharedReference, ValueTypeId,
66
backend::TurboTasksExecutionError,
77
event::{Event, EventListener},
88
};
@@ -243,9 +243,10 @@ pub enum CachedDataItem {
243243
cell: CellId,
244244
value: TypedSharedReference,
245245
},
246+
#[serde(skip)]
246247
TransientCellData {
247248
cell: CellId,
248-
value: TypedSharedReference,
249+
value: SharedReference,
249250
},
250251
CellTypeMaxIndex {
251252
cell_type: ValueTypeId,
@@ -369,7 +370,10 @@ pub enum CachedDataItem {
369370
impl CachedDataItem {
370371
pub fn cell_data(is_transient: bool, cell: CellId, value: TypedSharedReference) -> Self {
371372
if is_transient {
372-
CachedDataItem::TransientCellData { cell, value }
373+
CachedDataItem::TransientCellData {
374+
cell,
375+
value: value.into_untyped(),
376+
}
373377
} else {
374378
CachedDataItem::CellData { cell, value }
375379
}

0 commit comments

Comments
 (0)