Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chunking Refactoring #6160

Merged
merged 56 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
7c15077
remove omit_entries, it's unused and won't be used
sokra Oct 6, 2023
8812462
WIP: pulling chunk_content out of EcmascriptChunk
sokra Oct 6, 2023
6be06d7
Use downcast
jridgewell Oct 6, 2023
88afdf6
Delete optimization code
jridgewell Oct 7, 2023
ebd4583
Refactor CssChunk to pass in chunk items
jridgewell Oct 7, 2023
f58dbe8
Merge remote-tracking branch 'origin/main' into jrl-chunking-refactor-4
sokra Oct 9, 2023
3bae371
clippy
sokra Oct 9, 2023
ae6c756
update snapshots
sokra Oct 9, 2023
f83f722
update deps
sokra Oct 9, 2023
21e0c8c
WIP
sokra Oct 9, 2023
c3c77b6
update pnpm version
sokra Oct 10, 2023
ce19a49
implement async loader for build context
sokra Oct 10, 2023
3988e83
remove isolated parallel
sokra Oct 10, 2023
f427f8a
avoid duplicates with chunk_content
sokra Oct 10, 2023
99887fe
fix PassthroughModules handling
sokra Oct 10, 2023
786b590
workaround for compiler bug
sokra Oct 10, 2023
a41af45
Merge branch 'main' into jrl-chunking-refactor-5
sokra Oct 10, 2023
c86367e
Update snapshots
jridgewell Oct 11, 2023
a8cb13c
Merge remote-tracking branch 'origin/main' into jrl-chunking-refactor-5
jridgewell Oct 11, 2023
7e286c0
Update snapshots
jridgewell Oct 11, 2023
697fede
Merge branch 'main' into jrl-chunking-refactor-4
sokra Oct 11, 2023
3871d50
Merge branch 'jrl-chunking-refactor-4' into jrl-chunking-refactor-5
sokra Oct 11, 2023
aeb20a0
pass chunk_group_root with mdx
sokra Oct 11, 2023
589173d
update snapshots
sokra Oct 11, 2023
dfa561b
Merge branch 'jrl-chunking-refactor-4' into jrl-chunking-refactor-5
sokra Oct 11, 2023
29f49fd
fixup: pass chunk_group_root with mdx
sokra Oct 11, 2023
bea10e0
remove println
sokra Oct 11, 2023
6e0e513
chunk_group_root doesn't need to be hashed
sokra Oct 11, 2023
c51ed8e
update snapshots
sokra Oct 11, 2023
2e9581a
Add splitting heuristic
sokra Oct 11, 2023
dd52095
remove chunk ident, and name chunks only based on content
sokra Oct 11, 2023
2046f59
clippy
sokra Oct 11, 2023
0d124ab
add tracing to chunking and fix infinite loop
sokra Oct 11, 2023
8a5811c
fix conflicting writes
sokra Oct 11, 2023
83034a0
update snapshots
sokra Oct 11, 2023
a579800
clippy
sokra Oct 11, 2023
0133644
Fix clippy
jridgewell Oct 11, 2023
940f2c4
Clippy fix
jridgewell Oct 11, 2023
9dc1f6a
Clippy fix
jridgewell Oct 12, 2023
77a4075
documentation, cleanup
sokra Oct 12, 2023
6ef0cc7
improve size heuristic
sokra Oct 12, 2023
181e0da
extract common code
sokra Oct 12, 2023
bf820f1
optimize chunk_group parallelism
sokra Oct 12, 2023
02d8c8b
minor improvements to chunking
sokra Oct 12, 2023
dfb6c76
compute async module status in chunk group
sokra Oct 12, 2023
2761f75
pass async module info to chunk creation
sokra Oct 12, 2023
7854ffa
make keyed_cell take any TaskInput as key
sokra Oct 12, 2023
c891db1
remove chunk_group_root, remove AsynModule::is_async
sokra Oct 12, 2023
913aeca
bugfixes
sokra Oct 12, 2023
f37a0e9
fix double keyed_cell
sokra Oct 12, 2023
e207f31
put async loaders into separate chunks
sokra Oct 12, 2023
77d85b0
Lint fixes
jridgewell Oct 12, 2023
fed0773
Fix async module propagation
jridgewell Oct 13, 2023
94dbb45
bugfixes and snapshot updates
sokra Oct 13, 2023
1583c81
Merge remote-tracking branch 'origin/main' into jrl-chunking-refactor-7
sokra Oct 13, 2023
370614e
update lockfile
sokra Oct 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions crates/turbo-tasks/src/keyed_cell.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use anyhow::Result;

use crate::{
self as turbo_tasks, macro_helpers::find_cell_by_type, manager::current_task,
ConcreteTaskInput, CurrentCellRef, RawVc, TaskId, TaskInput, ValueTypeId, Vc, VcValueType,
};

#[turbo_tasks::value]
struct KeyedCell {
cell: RawVc,
#[turbo_tasks(trace_ignore, debug_ignore)]
cell_ref: CurrentCellRef,
}

impl KeyedCell {}

#[turbo_tasks::value_impl]
impl KeyedCell {
#[turbo_tasks::function]
fn new(_task: TaskId, _key: ConcreteTaskInput, value_type_id: ValueTypeId) -> Vc<Self> {
let cell_ref = find_cell_by_type(value_type_id);
KeyedCell {
cell: cell_ref.into(),
cell_ref,
}
.cell()
}
}

/// Cells a value in a cell with a given key. A key MUST only be used once per
/// function.
///
/// Usually calling [Vc::cell] will create cells for a give type based on the
/// call order of [Vc::cell]. But this can yield to over-invalidation when the
/// number of cells changes. e. g. not doing the first [Vc::cell] call will move
/// all remaining values into different cells, causing invalidation of all of
/// them.
///
/// A keyed cell avoids this problem by not using call order, but a key instead.
///
/// Internally it creates a new Task based on the key and cells the value into
/// that task. This is a implementation detail and might change in the future.
pub async fn keyed_cell<T: PartialEq + Eq + VcValueType, K: TaskInput>(
key: K,
content: T,
) -> Result<Vc<T>> {
let cell = KeyedCell::new(
current_task("keyed_cell"),
key.into_concrete(),
T::get_value_type_id(),
)
.await?;
cell.cell_ref.compare_and_update_shared(content);
Ok(cell.cell.into())
}
8 changes: 5 additions & 3 deletions crates/turbo-tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mod id;
mod id_factory;
mod invalidation;
mod join_iter_ext;
mod keyed_cell;
#[doc(hidden)]
pub mod macro_helpers;
mod magic_any;
Expand Down Expand Up @@ -85,11 +86,12 @@ pub use invalidation::{
DynamicEqHash, InvalidationReason, InvalidationReasonKind, InvalidationReasonSet,
};
pub use join_iter_ext::{JoinIterExt, TryFlatJoinIterExt, TryJoinIterExt};
pub use keyed_cell::keyed_cell;
pub use manager::{
dynamic_call, emit, get_invalidator, mark_finished, mark_stateful, run_once,
run_once_with_reason, spawn_blocking, spawn_thread, trait_call, turbo_tasks, Invalidator,
StatsType, TaskIdProvider, TurboTasks, TurboTasksApi, TurboTasksBackendApi, TurboTasksCallApi,
Unused, UpdateInfo,
run_once_with_reason, spawn_blocking, spawn_thread, trait_call, turbo_tasks, CurrentCellRef,
Invalidator, StatsType, TaskIdProvider, TurboTasks, TurboTasksApi, TurboTasksBackendApi,
TurboTasksCallApi, Unused, UpdateInfo,
};
pub use native_function::NativeFunction;
use nohash_hasher::BuildNoHashHasher;
Expand Down
4 changes: 2 additions & 2 deletions crates/turbo-tasks/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ impl<B: Backend + 'static> TaskIdProvider for TurboTasks<B> {
}
}

fn current_task(from: &str) -> TaskId {
pub(crate) fn current_task(from: &str) -> TaskId {
match CURRENT_TASK_ID.try_with(|id| *id) {
Ok(id) => id,
Err(_) => panic!(
Expand Down Expand Up @@ -1478,7 +1478,7 @@ pub(crate) async fn read_task_cell(
}
}

#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct CurrentCellRef {
current_task: TaskId,
index: CellId,
Expand Down
40 changes: 38 additions & 2 deletions crates/turbo-tasks/src/task/task_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use anyhow::{anyhow, bail, Result};

use super::concrete_task_input::TransientSharedValue;
use crate::{
magic_any::MagicAny, ConcreteTaskInput, RawVc, SharedValue, TransientInstance, TransientValue,
TypedForInput, Value, Vc, VcValueType,
magic_any::MagicAny, ConcreteTaskInput, RawVc, SharedValue, TaskId, TransientInstance,
TransientValue, TypedForInput, Value, ValueTypeId, Vc, VcValueType,
};

/// Trait to implement in order for a type to be accepted as a
Expand All @@ -21,6 +21,16 @@ pub trait TaskInput: Send + Sync + Clone {
fn into_concrete(self) -> ConcreteTaskInput;
}

impl TaskInput for ConcreteTaskInput {
fn try_from_concrete(input: &ConcreteTaskInput) -> Result<Self> {
Ok(input.clone())
}

fn into_concrete(self) -> ConcreteTaskInput {
self
}
}

impl TaskInput for String {
fn try_from_concrete(input: &ConcreteTaskInput) -> Result<Self> {
match input {
Expand Down Expand Up @@ -148,6 +158,32 @@ impl TaskInput for usize {
}
}

impl TaskInput for ValueTypeId {
fn try_from_concrete(value: &ConcreteTaskInput) -> Result<Self> {
match value {
ConcreteTaskInput::Usize(value) => Ok(ValueTypeId::from(*value)),
_ => bail!("invalid task input type, expected ValueTypeId"),
}
}

fn into_concrete(self) -> ConcreteTaskInput {
ConcreteTaskInput::Usize(*self)
}
}

impl TaskInput for TaskId {
fn try_from_concrete(value: &ConcreteTaskInput) -> Result<Self> {
match value {
ConcreteTaskInput::Usize(value) => Ok(TaskId::from(*value)),
_ => bail!("invalid task input type, expected TaskId"),
}
}

fn into_concrete(self) -> ConcreteTaskInput {
ConcreteTaskInput::Usize(*self)
}
}

impl<T> TaskInput for Option<T>
where
T: TaskInput,
Expand Down
Loading
Loading