Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
14cae650
Commit
14cae650
authored
Jan 05, 2026
by
Tobias Koppers
Committed by
Tobias Koppers
Jan 13, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix priority inferring to use priority when invalidating the task instead of when scheduling it
parent
7267199a
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
87 additions
and
60 deletions
+87
-60
mod.rs
turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
+10
-6
aggregation_update.rs
...tasks-backend/src/backend/operation/aggregation_update.rs
+10
-7
connect_child.rs
...urbo-tasks-backend/src/backend/operation/connect_child.rs
+2
-2
invalidate.rs
...s/turbo-tasks-backend/src/backend/operation/invalidate.rs
+23
-18
mod.rs
...k/crates/turbo-tasks-backend/src/backend/operation/mod.rs
+24
-12
data.rs
turbopack/crates/turbo-tasks-backend/src/data.rs
+2
-2
manager.rs
turbopack/crates/turbo-tasks/src/manager.rs
+16
-13
No files found.
turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
View file @
14cae650
...
...
@@ -573,7 +573,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
// Check the dirty count of the root node
let
has_dirty_containers
=
task
.has_dirty_containers
();
if
has_dirty_containers
||
is_dirty
{
if
has_dirty_containers
||
is_dirty
.is_some
()
{
let
activeness
=
get_mut!
(
task
,
Activeness
);
let
mut
task_ids_to_schedule
:
Vec
<
_
>
=
Vec
::
new
();
// When there are dirty task, subscribe to the all_clean_event
...
...
@@ -639,7 +639,11 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
let
has_dirty_containers
=
task
.has_dirty_containers
();
let
task_description
=
ctx
.get_task_description
(
task_id
);
let
is_dirty_label
=
if
is_dirty
{
", dirty"
}
else
{
""
};
let
is_dirty_label
=
if
let
Some
(
parent_priority
)
=
is_dirty
{
format!
(
", dirty({parent_priority})"
)
}
else
{
format!
(
""
)
};
let
has_dirty_containers_label
=
if
has_dirty_containers
{
", dirty containers"
}
else
{
...
...
@@ -791,7 +795,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
// It's not possible that the task is InProgress at this point. If it is InProgress {
// done: true } it must have Output and would early return.
task
.add_new
(
item
);
ctx
.schedule_task
(
task
);
ctx
.schedule_task
(
task
,
TaskPriority
::
Initial
);
Ok
(
Err
(
listener
))
}
...
...
@@ -982,7 +986,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
TaskExecutionReason
::
CellNotAvailable
,
||
self
.get_task_desc_fn
(
task_id
),
));
ctx
.schedule_task
(
task
);
ctx
.schedule_task
(
task
,
TaskPriority
::
Initial
);
Ok
(
Err
(
listener
))
}
...
...
@@ -2490,7 +2494,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
let
old_dirtyness
=
get!
(
task
,
Dirty
)
.cloned
();
let
(
old_self_dirty
,
old_current_session_self_clean
)
=
match
old_dirtyness
{
None
=>
(
false
,
false
),
Some
(
Dirtyness
::
Dirty
)
=>
(
true
,
false
),
Some
(
Dirtyness
::
Dirty
(
_
)
)
=>
(
true
,
false
),
Some
(
Dirtyness
::
SessionDependent
)
=>
{
let
clean_in_current_session
=
get!
(
task
,
CurrentSessionClean
)
.is_some
();
(
true
,
clean_in_current_session
)
...
...
@@ -2995,7 +2999,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
let
mut
task
=
ctx
.task
(
task_id
,
TaskDataCategory
::
All
);
let
is_dirty
=
task
.is_dirty
();
let
has_dirty_containers
=
task
.has_dirty_containers
();
if
is_dirty
||
has_dirty_containers
{
if
is_dirty
.is_some
()
||
has_dirty_containers
{
if
let
Some
(
activeness_state
)
=
get_mut!
(
task
,
Activeness
)
{
// We will finish the task, but it would be removed after the task is done
activeness_state
.unset_root_type
();
...
...
turbopack/crates/turbo-tasks-backend/src/backend/operation/aggregation_update.rs
View file @
14cae650
...
...
@@ -20,7 +20,7 @@ use smallvec::{SmallVec, smallvec};
feature
=
"trace_find_and_schedule"
))]
use
tracing
::{
span
::
Span
,
trace_span
};
use
turbo_tasks
::{
FxIndexMap
,
TaskExecutionReason
,
TaskId
};
use
turbo_tasks
::{
FxIndexMap
,
TaskExecutionReason
,
TaskId
,
TaskPriority
};
#[cfg(feature
=
"trace_task_dirty"
)]
use
crate
::
backend
::
operation
::
invalidate
::
TaskDirtyCause
;
...
...
@@ -1498,10 +1498,13 @@ impl AggregationUpdateQueue {
)
{
// Task need to be scheduled if it's dirty or doesn't have output
let
dirty
=
task
.is_dirty
();
let
should_schedule
=
if
dirty
{
Some
(
TaskExecutionReason
::
ActivateDirty
)
let
should_schedule
=
if
let
Some
(
parent_priority
)
=
dirty
{
Some
(
(
TaskExecutionReason
::
ActivateDirty
,
parent_priority
)
)
}
else
if
!
task
.has_key
(
&
CachedDataItemKey
::
Output
{})
{
Some
(
TaskExecutionReason
::
ActivateInitial
)
Some
((
TaskExecutionReason
::
ActivateInitial
,
TaskPriority
::
initial
(),
))
}
else
{
None
};
...
...
@@ -1512,7 +1515,7 @@ impl AggregationUpdateQueue {
if
!
is_active_until_clean
{
let
mut
dirty_containers
=
task
.dirty_containers
()
.peekable
();
let
is_empty
=
dirty_containers
.peek
()
.is_none
();
if
!
is_empty
||
dirty
{
if
!
is_empty
||
dirty
.is_some
()
{
self
.extend_find_and_schedule_dirty
(
dirty_containers
);
let
activeness_state
=
...
...
@@ -1520,11 +1523,11 @@ impl AggregationUpdateQueue {
activeness_state
.set_active_until_clean
();
}
}
if
let
Some
(
reason
)
=
should_schedule
{
if
let
Some
(
(
reason
,
parent_priority
)
)
=
should_schedule
{
let
description
=
||
ctx
.get_task_desc_fn
(
task_id
);
if
task
.add
(
CachedDataItem
::
new_scheduled
(
reason
,
description
))
{
drop
(
task
);
ctx
.schedule
(
task_id
);
ctx
.schedule
(
task_id
,
parent_priority
);
}
}
}
...
...
turbopack/crates/turbo-tasks-backend/src/backend/operation/connect_child.rs
View file @
14cae650
use
bincode
::{
Decode
,
Encode
};
use
turbo_tasks
::{
TaskExecutionReason
,
TaskId
};
use
turbo_tasks
::{
TaskExecutionReason
,
TaskId
,
TaskPriority
};
use
crate
::{
backend
::{
...
...
@@ -74,7 +74,7 @@ impl ConnectChildOperation {
||
ctx
.get_task_desc_fn
(
child_task_id
),
))
{
ctx
.schedule_task
(
child_task
);
ctx
.schedule_task
(
child_task
,
TaskPriority
::
initial
()
);
}
}
...
...
turbopack/crates/turbo-tasks-backend/src/backend/operation/invalidate.rs
View file @
14cae650
...
...
@@ -13,10 +13,7 @@ use crate::{
},
storage
::{
get
,
get_mut
,
remove
},
},
data
::{
CachedDataItem
,
CachedDataItemKey
,
CachedDataItemValue
,
Dirtyness
,
InProgressState
,
InProgressStateInner
,
},
data
::{
CachedDataItem
,
CachedDataItemKey
,
Dirtyness
,
InProgressState
,
InProgressStateInner
},
};
#[derive(Encode,
Decode,
Clone,
Default)]
...
...
@@ -247,13 +244,9 @@ pub fn make_task_dirty_internal(
.entered
();
*
stale
=
true
;
}
let
old
=
task
.insert
(
CachedDataItem
::
Dirty
{
value
:
Dirtyness
::
Dirty
,
});
let
(
old_self_dirty
,
old_current_session_self_clean
)
=
match
old
{
Some
(
CachedDataItemValue
::
Dirty
{
value
:
Dirtyness
::
Dirty
,
})
=>
{
let
current
=
get!
(
task
,
Dirty
);
let
(
old_self_dirty
,
old_current_session_self_clean
,
parent_priority
)
=
match
current
{
Some
(
Dirtyness
::
Dirty
(
current_priority
))
=>
{
#[cfg(feature
=
"trace_task_dirty"
)]
let
_span
=
tracing
::
trace_span!
(
"task already dirty"
,
...
...
@@ -263,17 +256,26 @@ pub fn make_task_dirty_internal(
)
.entered
();
// already dirty
let
parent_priority
=
ctx
.get_current_task_priority
();
if
current_priority
>=
&
parent_priority
{
// Update the priority to be the lower one
task
.insert
(
CachedDataItem
::
Dirty
{
value
:
Dirtyness
::
Dirty
(
parent_priority
),
});
}
return
;
}
Some
(
CachedDataItemValue
::
Dirty
{
value
:
Dirtyness
::
SessionDependent
,
})
=>
{
Some
(
Dirtyness
::
SessionDependent
)
=>
{
let
parent_priority
=
ctx
.get_current_task_priority
();
task
.insert
(
CachedDataItem
::
Dirty
{
value
:
Dirtyness
::
Dirty
(
parent_priority
),
});
// It was a session-dependent dirty before, so we need to remove that clean count
let
was_current_session_clean
=
remove!
(
task
,
CurrentSessionClean
)
.is_some
();
if
was_current_session_clean
{
// There was a clean count for a session. If it was the current session, we need to
// propagate that change.
(
true
,
true
)
(
true
,
true
,
parent_priority
)
}
else
{
#[cfg(feature
=
"trace_task_dirty"
)]
let
_span
=
tracing
::
trace_span!
(
...
...
@@ -287,10 +289,13 @@ pub fn make_task_dirty_internal(
}
}
None
=>
{
let
parent_priority
=
ctx
.get_current_task_priority
();
task
.insert
(
CachedDataItem
::
Dirty
{
value
:
Dirtyness
::
Dirty
(
parent_priority
),
});
// It was clean before, so we need to increase the dirty count
(
false
,
false
)
(
false
,
false
,
parent_priority
)
}
_
=>
unreachable!
(),
};
let
new_self_dirty
=
true
;
...
...
@@ -343,7 +348,7 @@ pub fn make_task_dirty_internal(
))
{
drop
(
task
);
let
task
=
ctx
.task
(
task_id
,
TaskDataCategory
::
All
);
ctx
.schedule_task
(
task
);
ctx
.schedule_task
(
task
,
parent_priority
);
}
}
}
turbopack/crates/turbo-tasks-backend/src/backend/operation/mod.rs
View file @
14cae650
...
...
@@ -79,8 +79,9 @@ pub trait ExecuteContext<'e>: Sized {
task_id2
:
TaskId
,
category
:
TaskDataCategory
,
)
->
(
Self
::
TaskGuardImpl
,
Self
::
TaskGuardImpl
);
fn
schedule
(
&
mut
self
,
task_id
:
TaskId
);
fn
schedule_task
(
&
self
,
task
:
Self
::
TaskGuardImpl
);
fn
schedule
(
&
mut
self
,
task_id
:
TaskId
,
parent_priority
:
TaskPriority
);
fn
schedule_task
(
&
self
,
task
:
Self
::
TaskGuardImpl
,
parent_priority
:
TaskPriority
);
fn
get_current_task_priority
(
&
self
)
->
TaskPriority
;
fn
operation_suspend_point
<
T
>
(
&
mut
self
,
op
:
&
T
)
where
T
:
Clone
+
Into
<
AnyOperation
>
;
...
...
@@ -559,18 +560,23 @@ where
)
}
fn
schedule
(
&
mut
self
,
task_id
:
TaskId
)
{
fn
schedule
(
&
mut
self
,
task_id
:
TaskId
,
parent_priority
:
TaskPriority
)
{
let
task
=
self
.task
(
task_id
,
TaskDataCategory
::
All
);
self
.schedule_task
(
task
);
self
.schedule_task
(
task
,
parent_priority
);
}
fn
schedule_task
(
&
self
,
task
:
Self
::
TaskGuardImpl
)
{
fn
schedule_task
(
&
self
,
task
:
Self
::
TaskGuardImpl
,
parent_priority
:
TaskPriority
)
{
let
priority
=
if
get!
(
task
,
Output
)
.is_some
()
{
TaskPriority
::
invalidation
(
get!
(
task
,
LeafDistance
)
.copied
()
.unwrap_or_default
()
.min
)
}
else
{
TaskPriority
::
initial
()
};
self
.turbo_tasks
.schedule
(
task
.id
(),
priority
);
self
.turbo_tasks
.schedule
(
task
.id
(),
priority
.in_parent
(
parent_priority
));
}
fn
get_current_task_priority
(
&
self
)
->
TaskPriority
{
self
.turbo_tasks
.get_current_task_priority
()
}
fn
operation_suspend_point
<
T
:
Clone
+
Into
<
AnyOperation
>>
(
&
mut
self
,
op
:
&
T
)
{
...
...
@@ -674,15 +680,21 @@ pub trait TaskGuard: Debug {
fn
is_immutable
(
&
self
)
->
bool
{
self
.has_key
(
&
CachedDataItemKey
::
Immutable
{})
}
fn
is_dirty
(
&
self
)
->
bool
{
get!
(
self
,
Dirty
)
.is_some_and
(|
dirtyness
|
match
dirtyness
{
Dirtyness
::
Dirty
=>
true
,
Dirtyness
::
SessionDependent
=>
get!
(
self
,
CurrentSessionClean
)
.is_none
(),
fn
is_dirty
(
&
self
)
->
Option
<
TaskPriority
>
{
get!
(
self
,
Dirty
)
.and_then
(|
dirtyness
|
match
dirtyness
{
Dirtyness
::
Dirty
(
priority
)
=>
Some
(
*
priority
),
Dirtyness
::
SessionDependent
=>
{
if
get!
(
self
,
CurrentSessionClean
)
.is_none
()
{
Some
(
TaskPriority
::
initial
())
}
else
{
None
}
}
})
}
fn
dirtyness_and_session
(
&
self
)
->
Option
<
(
Dirtyness
,
bool
)
>
{
match
get!
(
self
,
Dirty
)
?
{
Dirtyness
::
Dirty
=>
Some
((
Dirtyness
::
Dirty
,
false
)),
Dirtyness
::
Dirty
(
priority
)
=>
Some
((
Dirtyness
::
Dirty
(
*
priority
)
,
false
)),
Dirtyness
::
SessionDependent
=>
Some
((
Dirtyness
::
SessionDependent
,
get!
(
self
,
CurrentSessionClean
)
.is_some
(),
...
...
@@ -693,7 +705,7 @@ pub trait TaskGuard: Debug {
fn
dirty
(
&
self
)
->
(
bool
,
bool
)
{
match
get!
(
self
,
Dirty
)
{
None
=>
(
false
,
false
),
Some
(
Dirtyness
::
Dirty
)
=>
(
true
,
false
),
Some
(
Dirtyness
::
Dirty
(
_
)
)
=>
(
true
,
false
),
Some
(
Dirtyness
::
SessionDependent
)
=>
(
true
,
get!
(
self
,
CurrentSessionClean
)
.is_some
()),
}
}
...
...
turbopack/crates/turbo-tasks-backend/src/data.rs
View file @
14cae650
use
bincode
::{
Decode
,
Encode
};
use
rustc_hash
::
FxHashSet
;
use
turbo_tasks
::{
CellId
,
KeyValuePair
,
SharedReference
,
TaskExecutionReason
,
TaskId
,
TraitTypeId
,
CellId
,
KeyValuePair
,
SharedReference
,
TaskExecutionReason
,
TaskId
,
T
askPriority
,
T
raitTypeId
,
TypedSharedReference
,
ValueTypeId
,
backend
::
TurboTasksExecutionError
,
event
::{
Event
,
EventListener
},
...
...
@@ -142,7 +142,7 @@ impl Eq for ActivenessState {}
#[derive(Debug,
Clone,
Copy,
Encode,
Decode,
PartialEq,
Eq)]
pub
enum
Dirtyness
{
Dirty
,
Dirty
(
TaskPriority
)
,
SessionDependent
,
}
...
...
turbopack/crates/turbo-tasks/src/manager.rs
View file @
14cae650
...
...
@@ -244,6 +244,9 @@ pub trait TurboTasksBackendApi<B: Backend + 'static>: TurboTasksCallApi + Sync +
/// Schedule a task for execution.
fn
schedule
(
&
self
,
task
:
TaskId
,
priority
:
TaskPriority
);
/// Returns the priority of the current task.
fn
get_current_task_priority
(
&
self
)
->
TaskPriority
;
/// Schedule a foreground backend job for execution.
fn
schedule_backend_foreground_job
(
&
self
,
job
:
B
::
BackendJob
);
...
...
@@ -399,10 +402,13 @@ impl Display for ReadTracking {
}
}
#[derive(Clone,
Copy,
Debug,
Eq,
PartialEq,
Ord,
PartialOrd)]
#[derive(
Encode,
Decode,
Default,
Clone,
Copy,
Debug,
Eq,
PartialEq,
Ord,
PartialOrd)]
pub
enum
TaskPriority
{
#[default]
Initial
,
Invalidation
{
priority
:
Reverse
<
u32
>
},
Invalidation
{
priority
:
Reverse
<
u32
>
,
},
}
impl
TaskPriority
{
...
...
@@ -416,13 +422,13 @@ impl TaskPriority {
Self
::
Initial
}
pub
fn
in_parent
(
&
self
,
get_parent_priority
:
impl
FnOnce
()
->
TaskPriority
)
->
Self
{
pub
fn
in_parent
(
&
self
,
parent_priority
:
TaskPriority
)
->
Self
{
match
self
{
TaskPriority
::
Initial
=>
Self
::
Initial
,
TaskPriority
::
Invalidation
{
priority
}
=>
{
if
let
TaskPriority
::
Invalidation
{
priority
:
parent_priority
,
}
=
get_parent_priority
()
}
=
parent_priority
&&
priority
.
0
<
parent_priority
.
0
{
Self
::
Invalidation
{
...
...
@@ -821,15 +827,6 @@ impl<B: Backend + 'static> TurboTasks<B> {
self
.begin_foreground_job
();
self
.scheduled_tasks
.fetch_add
(
1
,
Ordering
::
AcqRel
);
let
priority
=
priority
.in_parent
(||
{
CURRENT_TASK_STATE
.try_with
(|
task_state
|
{
let
task_state
=
task_state
.read
()
.unwrap
();
task_state
.priority
})
.unwrap_or
(
TaskPriority
::
initial
())
});
self
.priority_runner
.schedule
(
&
self
.pin
(),
ScheduledTask
::
Task
{
...
...
@@ -1625,6 +1622,12 @@ impl<B: Backend + 'static> TurboTasksBackendApi<B> for TurboTasks<B> {
self
.schedule
(
task
,
priority
)
}
fn
get_current_task_priority
(
&
self
)
->
TaskPriority
{
CURRENT_TASK_STATE
.try_with
(|
task_state
|
task_state
.read
()
.unwrap
()
.priority
)
.unwrap_or
(
TaskPriority
::
initial
())
}
fn
program_duration_until
(
&
self
,
instant
:
Instant
)
->
Duration
{
instant
-
self
.program_start
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment