@@ -500,6 +500,9 @@ impl TaskStorage {
500500 }
501501
502502 // This is common after a round of eviction we end up with tasks with only transient state
503+ // There is no need to search for it, we can just assume any task in this state is preserved
504+ // for a reason. NOTE: new tasks have the restored flags set as part of construction so the
505+ // only way for a task to end up in this situation is through eviction
503506 if !flags. data_restored ( ) && !flags. meta_restored ( ) {
504507 return (
505508 key_evictability,
@@ -510,7 +513,8 @@ impl TaskStorage {
510513 // Back off if another thread is currently restoring this task's data from
511514 // disk. Without this check, eviction could clear data that was already
512515 // determined to be "restored" by the restoring thread (which released the
513- // lock to do I/O), causing the restoring thread to skip re-reading it.
516+ // lock to do I/O), causing the restoring thread to skip re-reading it. Instead we respect
517+ // in flight restoration
514518 if flags. meta_restoring ( ) || flags. data_restoring ( ) {
515519 return (
516520 key_evictability,
@@ -526,6 +530,8 @@ impl TaskStorage {
526530 && !flags. data_modified_during_snapshot ( )
527531 && self . transient_cell_data ( ) . is_none_or ( |m| m. is_empty ( ) )
528532 // If transient tasks depend on our cells or output we cannot be evicted
533+
534+ // TODO: this is the most expensive part of the scan since there can be many cell and output dependents as well as many cells
529535 && self
530536 . cell_dependents ( )
531537 . is_none_or ( |cd| !cd. iter ( ) . any ( |( _, _, t) | t. is_transient ( ) ) )
@@ -543,11 +549,12 @@ impl TaskStorage {
543549 let meta_evictable = flags. meta_restored ( )
544550 && !flags. meta_modified ( )
545551 && !flags. meta_modified_during_snapshot ( )
552+ && self . get_output ( ) . is_none_or ( |o| !o. is_transient ( ) )
553+ // TODO: this is the most expensive part of the scan since there can be many dependents and uppers
546554 && self
547555 . collectibles_dependents ( )
548556 . is_none_or ( |d| !d. iter ( ) . any ( |( _trait_id, task) | task. is_transient ( ) ) )
549- && !self . upper ( ) . iter ( ) . any ( |( k, _) | k. is_transient ( ) )
550- && self . get_output ( ) . is_none_or ( |o| !o. is_transient ( ) ) ;
557+ && !self . upper ( ) . iter ( ) . any ( |( k, _) | k. is_transient ( ) ) ;
551558
552559 // === Combined decision ===
553560 (
0 commit comments