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
ed631bbc
Commit
ed631bbc
authored
Apr 04, 2026
by
Luke Sandberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tracing improvements
parent
bbfc2280
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
169 additions
and
87 deletions
+169
-87
mod.rs
turbopack/crates/turbo-persistence/benches/mod.rs
+3
-0
db.rs
turbopack/crates/turbo-persistence/src/db.rs
+1
-1
sst_filter.rs
turbopack/crates/turbo-persistence/src/sst_filter.rs
+6
-0
tests.rs
turbopack/crates/turbo-persistence/src/tests.rs
+2
-0
mod.rs
turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
+20
-15
aggregation_update.rs
...tasks-backend/src/backend/operation/aggregation_update.rs
+61
-44
mod.rs
...k/crates/turbo-tasks-backend/src/backend/operation/mod.rs
+75
-27
update_cell.rs
.../turbo-tasks-backend/src/backend/operation/update_cell.rs
+1
-0
No files found.
turbopack/crates/turbo-persistence/benches/mod.rs
View file @
ed631bbc
...
...
@@ -576,6 +576,7 @@ fn prefill_multi_value_database(
)
->
Result
<
Vec
<
Box
<
[
u8
]
>>>
{
let
db_config
=
TpDbConfig
{
family_configs
:
[
FamilyConfig
{
name
:
"test"
,
kind
:
FamilyKind
::
MultiValue
,
}],
};
...
...
@@ -648,6 +649,7 @@ fn setup_prefilled_multi_value_db(
fn
open_multi_value_db
(
path
:
&
Path
)
->
TurboPersistence
<
SerialScheduler
,
1
>
{
let
db_config
=
TpDbConfig
{
family_configs
:
[
FamilyConfig
{
name
:
"test"
,
kind
:
FamilyKind
::
MultiValue
,
}],
};
...
...
@@ -914,6 +916,7 @@ fn bench_write_multi_value(c: &mut Criterion) {
|(
tempdir
,
keys
,
random_data
)|
{
let
db_config
=
TpDbConfig
{
family_configs
:
[
FamilyConfig
{
name
:
"test"
,
kind
:
FamilyKind
::
MultiValue
,
}],
};
...
...
turbopack/crates/turbo-persistence/src/db.rs
View file @
ed631bbc
...
...
@@ -1573,7 +1573,7 @@ impl<S: ParallelScheduler, const FAMILIES: usize> TurboPersistence<S, FAMILIES>
}
let
span
=
tracing
::
trace_span!
(
"database batch read"
,
name
=
family
,
name
=
self
.config.family_configs
[
family
]
.name
,
keys
=
keys
.len
(),
not_found
=
tracing
::
field
::
Empty
,
deleted
=
tracing
::
field
::
Empty
,
...
...
turbopack/crates/turbo-persistence/src/sst_filter.rs
View file @
ed631bbc
...
...
@@ -67,3 +67,9 @@ impl SstFilter {
!
used
&&
!
meta
.has_active_entries
()
}
}
impl
Default
for
SstFilter
{
fn
default
()
->
Self
{
Self
::
new
()
}
}
turbopack/crates/turbo-persistence/src/tests.rs
View file @
ed631bbc
...
...
@@ -1521,6 +1521,7 @@ fn compaction_multi_value_preserves_different_values() -> Result<()> {
fn
multi_value_config
()
->
DbConfig
<
1
>
{
let
mut
config
=
DbConfig
::
<
1
>
::
default
();
config
.family_configs
[
0
]
=
FamilyConfig
{
name
:
"test"
,
kind
:
FamilyKind
::
MultiValue
,
};
config
...
...
@@ -2097,6 +2098,7 @@ fn compaction_deletes_blob_multi_value_tombstone() -> Result<()> {
let
config
=
DbConfig
{
family_configs
:
[
FamilyConfig
{
name
:
"test"
,
kind
:
FamilyKind
::
MultiValue
,
}],
};
...
...
turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
View file @
ed631bbc
...
...
@@ -1912,7 +1912,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
let
once_task
=
matches!
(
task_type
,
TaskType
::
Transient
(
ref
tt
)
if
matches!
(
&**
tt
,
TransientTask
::
Once
(
_
)));
if
let
Some
(
tasks
)
=
task
.prefetch
()
{
drop
(
task
);
ctx
.prepare_tasks
(
tasks
);
ctx
.prepare_tasks
(
tasks
,
"prefetch"
);
task
=
ctx
.task
(
task_id
,
TaskDataCategory
::
All
);
}
let
in_progress
=
task
.take_in_progress
()
?
;
...
...
@@ -2399,6 +2399,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
output_dependent_tasks
.iter
()
.map
(|
&
id
|
(
id
,
TaskDataCategory
::
All
)),
"invalidate output dependents"
,
);
}
...
...
@@ -2491,20 +2492,24 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
debug_assert!
(
!
new_children
.is_empty
());
let
mut
queue
=
AggregationUpdateQueue
::
new
();
ctx
.for_each_task_all
(
new_children
.iter
()
.copied
(),
|
child_task
,
ctx
|
{
if
!
child_task
.has_output
()
{
let
child_id
=
child_task
.id
();
make_task_dirty_internal
(
child_task
,
child_id
,
false
,
#[cfg(feature
=
"trace_task_dirty"
)]
TaskDirtyCause
::
InitialDirty
,
&
mut
queue
,
ctx
,
);
}
});
ctx
.for_each_task_all
(
new_children
.iter
()
.copied
(),
"unfinished children dirty"
,
|
child_task
,
ctx
|
{
if
!
child_task
.has_output
()
{
let
child_id
=
child_task
.id
();
make_task_dirty_internal
(
child_task
,
child_id
,
false
,
#[cfg(feature
=
"trace_task_dirty"
)]
TaskDirtyCause
::
InitialDirty
,
&
mut
queue
,
ctx
,
);
}
},
);
queue
.execute
(
ctx
);
}
...
...
turbopack/crates/turbo-tasks-backend/src/backend/operation/aggregation_update.rs
View file @
ed631bbc
...
...
@@ -1256,10 +1256,14 @@ impl AggregationUpdateQueue {
self
.find_and_schedule_dirty
(
jobs
,
ctx
);
false
}
else
if
!
self
.scheduled_tasks
.is_empty
()
{
ctx
.for_each_task_all
(
self
.scheduled_tasks
.keys
()
.copied
(),
|
task
,
ctx
|
{
let
parent_priority
=
self
.scheduled_tasks
[
&
task
.id
()];
ctx
.schedule_task
(
task
,
parent_priority
);
});
ctx
.for_each_task_all
(
self
.scheduled_tasks
.keys
()
.copied
(),
"schedule tasks"
,
|
task
,
ctx
|
{
let
parent_priority
=
self
.scheduled_tasks
[
&
task
.id
()];
ctx
.schedule_task
(
task
,
parent_priority
);
},
);
self
.scheduled_tasks
.clear
();
false
}
else
{
...
...
@@ -1444,18 +1448,22 @@ impl AggregationUpdateQueue {
.map
(|
job
|
(
job
.task_id
,
job
.span
.clone
()))
.collect
();
// For performance reasons this should stay `Meta` and not `All`
ctx
.for_each_task_meta
(
jobs
.into_iter
()
.map
(|
job
|
job
.task_id
),
|
task
,
ctx
|
{
let
task_id
=
task
.id
();
// Enter the enqueue-time span and create a per-task child span with the
// task description. Both guards must live until the end of the closure.
#[cfg(feature
=
"trace_find_and_schedule"
)]
let
_trace
=
(
spans
.remove
(
&
task_id
)
.flatten
()
.map
(|
s
|
s
.entered
()),
trace_span!
(
"find and schedule"
,
%
task_id
,
name
=
task
.get_task_description
())
.entered
(),
);
self
.find_and_schedule_dirty_internal
(
task_id
,
task
,
ctx
);
});
ctx
.for_each_task_meta
(
jobs
.into_iter
()
.map
(|
job
|
job
.task_id
),
"find and schedule dirty"
,
|
task
,
ctx
|
{
let
task_id
=
task
.id
();
// Enter the enqueue-time span and create a per-task child span with the
// task description. Both guards must live until the end of the closure.
#[cfg(feature
=
"trace_find_and_schedule"
)]
let
_trace
=
(
spans
.remove
(
&
task_id
)
.flatten
()
.map
(|
s
|
s
.entered
()),
trace_span!
(
"find and schedule"
,
%
task_id
,
name
=
task
.get_task_description
())
.entered
(),
);
self
.find_and_schedule_dirty_internal
(
task_id
,
task
,
ctx
);
},
);
}
fn
find_and_schedule_dirty_internal
(
...
...
@@ -1507,21 +1515,25 @@ impl AggregationUpdateQueue {
update
:
AggregatedDataUpdate
,
)
{
// For performance reasons this should stay `Meta` and not `All`
ctx
.for_each_task_meta
(
upper_ids
.iter
()
.copied
(),
|
mut
upper
,
ctx
|
{
let
diff
=
update
.apply
(
&
mut
upper
,
ctx
.should_track_activeness
(),
self
);
if
!
diff
.is_empty
()
{
let
upper_ids
=
get_uppers
(
&
upper
);
if
!
upper_ids
.is_empty
()
{
self
.push
(
AggregatedDataUpdateJob
{
upper_ids
,
update
:
diff
,
}
.into
(),
);
ctx
.for_each_task_meta
(
upper_ids
.iter
()
.copied
(),
"aggregated data update"
,
|
mut
upper
,
ctx
|
{
let
diff
=
update
.apply
(
&
mut
upper
,
ctx
.should_track_activeness
(),
self
);
if
!
diff
.is_empty
()
{
let
upper_ids
=
get_uppers
(
&
upper
);
if
!
upper_ids
.is_empty
()
{
self
.push
(
AggregatedDataUpdateJob
{
upper_ids
,
update
:
diff
,
}
.into
(),
);
}
}
}
}
);
}
,
);
}
fn
inner_of_uppers_lost_follower
(
...
...
@@ -1574,20 +1586,24 @@ impl AggregationUpdateQueue {
if
!
data
.is_empty
()
{
// remove data from upper
// For performance reasons this should stay `Meta` and not `All`
ctx
.for_each_task_meta
(
removed_uppers
.iter
()
.copied
(),
|
mut
upper
,
ctx
|
{
// STEP 6
let
diff
=
data
.apply
(
&
mut
upper
,
ctx
.should_track_activeness
(),
self
);
if
!
diff
.is_empty
()
{
let
upper_ids
=
get_uppers
(
&
upper
);
self
.push
(
AggregatedDataUpdateJob
{
upper_ids
,
update
:
diff
,
}
.into
(),
)
}
});
ctx
.for_each_task_meta
(
removed_uppers
.iter
()
.copied
(),
"remove data from uppers"
,
|
mut
upper
,
ctx
|
{
// STEP 6
let
diff
=
data
.apply
(
&
mut
upper
,
ctx
.should_track_activeness
(),
self
);
if
!
diff
.is_empty
()
{
let
upper_ids
=
get_uppers
(
&
upper
);
self
.push
(
AggregatedDataUpdateJob
{
upper_ids
,
update
:
diff
,
}
.into
(),
)
}
},
);
}
// STEP 7
if
!
followers
.is_empty
()
{
...
...
@@ -2061,6 +2077,7 @@ impl AggregationUpdateQueue {
upper_ids_with_min_aggregation_number
.iter
()
.map
(|(
entry
,
_
)|
entry
.task_id
()),
"add data to uppers"
,
|
mut
upper
,
ctx
|
{
// STEP 6d
if
has_data
{
...
...
turbopack/crates/turbo-tasks-backend/src/backend/operation/mod.rs
View file @
ed631bbc
...
...
@@ -13,6 +13,7 @@ use std::{
};
use
bincode
::{
Decode
,
Encode
};
use
tracing
::
trace_span
;
use
turbo_tasks
::{
CellId
,
FxIndexMap
,
TaskExecutionReason
,
TaskId
,
TaskPriority
,
TurboTasksBackendApi
,
TurboTasksCallApi
,
TypedSharedReference
,
backend
::
CachedTaskType
,
...
...
@@ -45,29 +46,35 @@ pub trait ExecuteContext<'e>: Sized {
fn
prepare_tasks
(
&
mut
self
,
task_ids
:
impl
IntoIterator
<
Item
=
(
TaskId
,
TaskDataCategory
)
>
+
Clone
,
reason
:
&
'static
str
,
);
fn
for_each_task
(
&
mut
self
,
task_ids
:
impl
IntoIterator
<
Item
=
(
TaskId
,
TaskDataCategory
)
>
,
reason
:
&
'static
str
,
func
:
impl
FnMut
(
Self
::
TaskGuardImpl
,
&
mut
Self
),
);
fn
for_each_task_meta
(
&
mut
self
,
task_ids
:
impl
IntoIterator
<
Item
=
TaskId
>
,
reason
:
&
'static
str
,
func
:
impl
FnMut
(
Self
::
TaskGuardImpl
,
&
mut
Self
),
)
{
self
.for_each_task
(
task_ids
.into_iter
()
.map
(|
id
|
(
id
,
TaskDataCategory
::
Meta
)),
reason
,
func
,
)
}
fn
for_each_task_all
(
&
mut
self
,
task_ids
:
impl
IntoIterator
<
Item
=
TaskId
>
,
reason
:
&
'static
str
,
func
:
impl
FnMut
(
Self
::
TaskGuardImpl
,
&
mut
Self
),
)
{
self
.for_each_task
(
task_ids
.into_iter
()
.map
(|
id
|
(
id
,
TaskDataCategory
::
All
)),
reason
,
func
,
)
}
...
...
@@ -199,6 +206,7 @@ impl<'e, B: BackingStorage> ExecuteContextImpl<'e, B> {
&
self
,
task_ids
:
&
[
TaskId
],
category
:
SpecificTaskDataCategory
,
reason
:
&
'static
str
,
)
->
Option
<
Vec
<
TaskStorage
>>
{
debug_assert!
(
task_ids
.len
()
>
1
,
...
...
@@ -208,6 +216,13 @@ impl<'e, B: BackingStorage> ExecuteContextImpl<'e, B> {
// If we don't need to restore, we return None
return
None
;
}
let
_span
=
trace_span!
(
"restore_task_data_batch"
,
reason
,
category
=
?
category
,
keys
=
task_ids
.len
(),
)
.entered
();
let
result
=
self
.backend
.backing_storage
...
...
@@ -230,6 +245,7 @@ impl<'e, B: BackingStorage> ExecuteContextImpl<'e, B> {
&
mut
self
,
task_ids
:
impl
IntoIterator
<
Item
=
(
TaskId
,
TaskDataCategory
)
>
,
call_prepared_task_callback_for_transient_tasks
:
bool
,
reason
:
&
'static
str
,
mut
prepared_task_callback
:
impl
FnMut
(
&
mut
Self
,
TaskId
,
...
...
@@ -237,6 +253,15 @@ impl<'e, B: BackingStorage> ExecuteContextImpl<'e, B> {
StorageWriteGuard
<
'e
>
,
),
)
{
let
span
=
trace_span!
(
"prepare_tasks_with_callback"
,
reason
,
requested_data
=
tracing
::
field
::
Empty
,
requested_meta
=
tracing
::
field
::
Empty
,
races_data
=
tracing
::
field
::
Empty
,
races_meta
=
tracing
::
field
::
Empty
,
);
let
_guard
=
span
.enter
();
let
mut
data_count
=
0
;
let
mut
meta_count
=
0
;
let
mut
all_count
=
0
;
...
...
@@ -267,6 +292,8 @@ impl<'e, B: BackingStorage> ExecuteContextImpl<'e, B> {
.collect
::
<
Vec
<
_
>>
();
data_count
+=
all_count
;
meta_count
+=
all_count
;
span
.record
(
"requested_data"
,
data_count
);
span
.record
(
"requested_meta"
,
meta_count
);
let
mut
tasks_to_restore_for_data
=
Vec
::
with_capacity
(
data_count
);
let
mut
tasks_to_restore_for_data_indicies
=
Vec
::
with_capacity
(
data_count
);
...
...
@@ -312,6 +339,7 @@ impl<'e, B: BackingStorage> ExecuteContextImpl<'e, B> {
if
let
Some
(
data
)
=
self
.restore_task_data_batch
(
&
tasks_to_restore_for_data
,
SpecificTaskDataCategory
::
Data
,
reason
,
)
{
data
.into_iter
()
.zip
(
tasks_to_restore_for_data_indicies
)
...
...
@@ -337,6 +365,7 @@ impl<'e, B: BackingStorage> ExecuteContextImpl<'e, B> {
if
let
Some
(
data
)
=
self
.restore_task_data_batch
(
&
tasks_to_restore_for_meta
,
SpecificTaskDataCategory
::
Meta
,
reason
,
)
{
data
.into_iter
()
.zip
(
tasks_to_restore_for_meta_indicies
)
...
...
@@ -351,6 +380,8 @@ impl<'e, B: BackingStorage> ExecuteContextImpl<'e, B> {
}
}
let
mut
races_data
=
0u32
;
let
mut
races_meta
=
0u32
;
for
(
task_id
,
category
,
storage_for_data
,
storage_for_meta
)
in
tasks
{
if
storage_for_data
.is_none
()
&&
storage_for_meta
.is_none
()
{
continue
;
...
...
@@ -359,18 +390,24 @@ impl<'e, B: BackingStorage> ExecuteContextImpl<'e, B> {
let
mut
task_type
=
None
;
let
mut
task
=
self
.backend.storage
.access_mut
(
task_id
);
if
let
Some
(
storage
)
=
storage_for_data
&&
!
task
.flags
.is_restored
(
TaskDataCategory
::
Data
)
{
task
.restore_from
(
storage
,
TaskDataCategory
::
Data
);
task
.flags
.set_restored
(
TaskDataCategory
::
Data
);
task_type
=
task
.get_persistent_task_type
()
.cloned
()
if
let
Some
(
storage
)
=
storage_for_data
{
if
!
task
.flags
.is_restored
(
TaskDataCategory
::
Data
)
{
task
.restore_from
(
storage
,
TaskDataCategory
::
Data
);
task
.flags
.set_restored
(
TaskDataCategory
::
Data
);
task_type
=
task
.get_persistent_task_type
()
.cloned
()
}
else
{
races_data
+=
1
;
span
.record
(
"races_data"
,
races_data
);
}
}
if
let
Some
(
storage
)
=
storage_for_meta
&&
!
task
.flags
.is_restored
(
TaskDataCategory
::
Meta
)
{
task
.restore_from
(
storage
,
TaskDataCategory
::
Meta
);
task
.flags
.set_restored
(
TaskDataCategory
::
Meta
);
if
let
Some
(
storage
)
=
storage_for_meta
{
if
!
task
.flags
.is_restored
(
TaskDataCategory
::
Meta
)
{
task
.restore_from
(
storage
,
TaskDataCategory
::
Meta
);
task
.flags
.set_restored
(
TaskDataCategory
::
Meta
);
}
else
{
races_meta
+=
1
;
span
.record
(
"races_meta"
,
races_meta
);
}
}
self
.task_lock_counter
.release
();
prepared_task_callback
(
self
,
task_id
,
category
,
task
);
...
...
@@ -446,30 +483,41 @@ impl<'e, B: BackingStorage> ExecuteContext<'e> for ExecuteContextImpl<'e, B> {
}
}
fn
prepare_tasks
(
&
mut
self
,
task_ids
:
impl
IntoIterator
<
Item
=
(
TaskId
,
TaskDataCategory
)
>
)
{
self
.prepare_tasks_with_callback
(
task_ids
,
false
,
|
_
,
_
,
_
,
_
|
{});
fn
prepare_tasks
(
&
mut
self
,
task_ids
:
impl
IntoIterator
<
Item
=
(
TaskId
,
TaskDataCategory
)
>
+
Clone
,
reason
:
&
'static
str
,
)
{
self
.prepare_tasks_with_callback
(
task_ids
,
false
,
reason
,
|
_
,
_
,
_
,
_
|
{});
}
fn
for_each_task
(
&
mut
self
,
task_ids
:
impl
IntoIterator
<
Item
=
(
TaskId
,
TaskDataCategory
)
>
,
reason
:
&
'static
str
,
mut
func
:
impl
FnMut
(
Self
::
TaskGuardImpl
,
&
mut
Self
),
)
{
let
task_lock_counter
=
self
.task_lock_counter
.clone
();
self
.prepare_tasks_with_callback
(
task_ids
,
true
,
|
this
,
task_id
,
_category
,
task
|
{
// prepare_tasks_with_callback releases the counter before calling this callback,
// so the counter is 0 here. Acquire for the TaskGuardImpl that will release on Drop.
task_lock_counter
.acquire
();
let
guard
=
TaskGuardImpl
{
task
,
task_id
,
#[cfg(debug_assertions)]
category
:
_category
,
task_lock_counter
:
task_lock_counter
.clone
(),
};
func
(
guard
,
this
);
});
self
.prepare_tasks_with_callback
(
task_ids
,
true
,
reason
,
|
this
,
task_id
,
_category
,
task
|
{
// prepare_tasks_with_callback releases the counter before calling this callback,
// so the counter is 0 here. Acquire for the TaskGuardImpl that will release on
// Drop.
task_lock_counter
.acquire
();
let
guard
=
TaskGuardImpl
{
task
,
task_id
,
#[cfg(debug_assertions)]
category
:
_category
,
task_lock_counter
:
task_lock_counter
.clone
(),
};
func
(
guard
,
this
);
},
);
}
fn
task_pair
(
...
...
turbopack/crates/turbo-tasks-backend/src/backend/operation/update_cell.rs
View file @
ed631bbc
...
...
@@ -153,6 +153,7 @@ impl UpdateCellOperation {
dependent_tasks
.keys
()
.map
(|
&
id
|
(
id
,
TaskDataCategory
::
All
)),
"invalidate cell dependents"
,
);
UpdateCellOperation
::
InvalidateWhenCellDependency
{
...
...
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