@@ -422,7 +422,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
422422 }
423423
424424 let mut ctx = self . execute_context ( turbo_tasks) ;
425- let mut task = ctx. task ( task_id, TaskDataCategory :: All ) ;
425+ let mut task = ctx. task ( task_id, TaskDataCategory :: Meta ) ;
426426
427427 fn listen_to_done_event < B : BackingStorage > (
428428 this : & TurboTasksBackendInner < B > ,
@@ -493,7 +493,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
493493 & mut ctx,
494494 ) ;
495495 }
496- task = ctx. task ( task_id, TaskDataCategory :: All ) ;
496+ task = ctx. task ( task_id, TaskDataCategory :: Meta ) ;
497497 }
498498
499499 let is_dirty =
@@ -1552,10 +1552,16 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
15521552
15531553 // Remove no longer existing cells and
15541554 // find all outdated data items (removed cells, outdated edges)
1555- removed_data. extend ( task. extract_if ( CachedDataItemType :: CellData , |key, _| {
1556- matches ! ( key, CachedDataItemKey :: CellData { cell } if cell_counters
1557- . get( & cell. type_id) . is_none_or( |start_index| cell. index >= * start_index) )
1558- } ) ) ;
1555+ // Note: For persistent tasks we only want to call extract_if when there are actual cells to
1556+ // remove to avoid tracking that as modification.
1557+ if task_id. is_transient ( ) || iter_many ! ( task, CellData { cell }
1558+ if cell_counters. get( & cell. type_id) . is_none_or( |start_index| cell. index >= * start_index) => cell
1559+ ) . count ( ) > 0 {
1560+ removed_data. extend ( task. extract_if ( CachedDataItemType :: CellData , |key, _| {
1561+ matches ! ( key, CachedDataItemKey :: CellData { cell } if cell_counters
1562+ . get( & cell. type_id) . is_none_or( |start_index| cell. index >= * start_index) )
1563+ } ) ) ;
1564+ }
15591565 if self . should_track_children ( ) {
15601566 old_edges. extend (
15611567 task. iter ( CachedDataItemType :: OutdatedCollectible )
@@ -1708,6 +1714,8 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
17081714 ) ) ;
17091715
17101716 // Update the dirty state
1717+ let old_dirty_state = get ! ( task, Dirty ) . copied ( ) ;
1718+
17111719 let new_dirty_state = if session_dependent {
17121720 Some ( DirtyState {
17131721 clean_in_session : Some ( self . session_id ) ,
@@ -1716,48 +1724,48 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
17161724 None
17171725 } ;
17181726
1719- let old_dirty = if let Some ( new_dirty_state) = new_dirty_state {
1720- task. insert ( CachedDataItem :: Dirty {
1721- value : new_dirty_state,
1722- } )
1723- } else {
1724- task. remove ( & CachedDataItemKey :: Dirty { } )
1725- } ;
1726-
1727- let old_dirty_state = old_dirty. map ( |old_dirty| match old_dirty {
1728- CachedDataItemValue :: Dirty { value } => value,
1729- _ => unreachable ! ( ) ,
1730- } ) ;
1731-
1732- let data_update = if self . should_track_children ( )
1733- && ( old_dirty_state. is_some ( ) || new_dirty_state. is_some ( ) )
1734- {
1735- let mut dirty_containers = get ! ( task, AggregatedDirtyContainerCount )
1736- . cloned ( )
1737- . unwrap_or_default ( ) ;
1738- if let Some ( old_dirty_state) = old_dirty_state {
1739- dirty_containers. update_with_dirty_state ( & old_dirty_state) ;
1727+ let data_update = if old_dirty_state != new_dirty_state {
1728+ if let Some ( new_dirty_state) = new_dirty_state {
1729+ task. insert ( CachedDataItem :: Dirty {
1730+ value : new_dirty_state,
1731+ } ) ;
1732+ } else {
1733+ task. remove ( & CachedDataItemKey :: Dirty { } ) ;
17401734 }
1741- let aggregated_update = match ( old_dirty_state, new_dirty_state) {
1742- ( None , None ) => unreachable ! ( ) ,
1743- ( Some ( old) , None ) => dirty_containers. undo_update_with_dirty_state ( & old) ,
1744- ( None , Some ( new) ) => dirty_containers. update_with_dirty_state ( & new) ,
1745- ( Some ( old) , Some ( new) ) => dirty_containers. replace_dirty_state ( & old, & new) ,
1746- } ;
1747- if !aggregated_update. is_zero ( ) {
1748- if aggregated_update. get ( self . session_id ) < 0 {
1749- if let Some ( root_state) = get_mut ! ( task, Activeness ) {
1750- root_state. all_clean_event . notify ( usize:: MAX ) ;
1751- root_state. unset_active_until_clean ( ) ;
1752- if root_state. is_empty ( ) {
1753- task. remove ( & CachedDataItemKey :: Activeness { } ) ;
1735+
1736+ if self . should_track_children ( )
1737+ && ( old_dirty_state. is_some ( ) || new_dirty_state. is_some ( ) )
1738+ {
1739+ let mut dirty_containers = get ! ( task, AggregatedDirtyContainerCount )
1740+ . cloned ( )
1741+ . unwrap_or_default ( ) ;
1742+ if let Some ( old_dirty_state) = old_dirty_state {
1743+ dirty_containers. update_with_dirty_state ( & old_dirty_state) ;
1744+ }
1745+ let aggregated_update = match ( old_dirty_state, new_dirty_state) {
1746+ ( None , None ) => unreachable ! ( ) ,
1747+ ( Some ( old) , None ) => dirty_containers. undo_update_with_dirty_state ( & old) ,
1748+ ( None , Some ( new) ) => dirty_containers. update_with_dirty_state ( & new) ,
1749+ ( Some ( old) , Some ( new) ) => dirty_containers. replace_dirty_state ( & old, & new) ,
1750+ } ;
1751+ if !aggregated_update. is_zero ( ) {
1752+ if aggregated_update. get ( self . session_id ) < 0 {
1753+ if let Some ( root_state) = get_mut ! ( task, Activeness ) {
1754+ root_state. all_clean_event . notify ( usize:: MAX ) ;
1755+ root_state. unset_active_until_clean ( ) ;
1756+ if root_state. is_empty ( ) {
1757+ task. remove ( & CachedDataItemKey :: Activeness { } ) ;
1758+ }
17541759 }
17551760 }
1761+ AggregationUpdateJob :: data_update (
1762+ & mut task,
1763+ AggregatedDataUpdate :: new ( )
1764+ . dirty_container_update ( task_id, aggregated_update) ,
1765+ )
1766+ } else {
1767+ None
17561768 }
1757- AggregationUpdateJob :: data_update (
1758- & mut task,
1759- AggregatedDataUpdate :: new ( ) . dirty_container_update ( task_id, aggregated_update) ,
1760- )
17611769 } else {
17621770 None
17631771 }
0 commit comments