Unverified Commit d546e251 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

fix(next): skip the per-pull server HMR operation without a baseline

Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent f56dfabf
...@@ -135,7 +135,7 @@ impl ChunkListUpdateBuilder { ...@@ -135,7 +135,7 @@ impl ChunkListUpdateBuilder {
} }
/// An update plus the baseline for the next pull. /// An update plus the baseline for the next pull.
#[derive(Debug, PartialEq, Eq, ValueDebugFormat, NonLocalValue)] #[derive(Clone, Debug, PartialEq, Eq, ValueDebugFormat, NonLocalValue)]
pub enum ServerHmrUpdate { pub enum ServerHmrUpdate {
/// No runtime update and the graph is equivalent. However, `to` may still advance the pull /// No runtime update and the graph is equivalent. However, `to` may still advance the pull
/// version. /// version.
...@@ -328,11 +328,11 @@ fn classify_server_hmr_update<'a>( ...@@ -328,11 +328,11 @@ fn classify_server_hmr_update<'a>(
/// Computes the update of a pull from its chunk lists, the pull baseline `from` and the version /// Computes the update of a pull from its chunk lists, the pull baseline `from` and the version
/// `to` of `chunk_lists`. /// `to` of `chunk_lists`.
/// ///
/// Must be called from the pull operation that also produced `chunk_lists` and `to`, so that the /// Without a baseline nothing is diffed. With a baseline, this must be called from the pull
/// update, `to` and the applied effects all come from the same settled state (see /// operation that also produced `chunk_lists` and `to`, so that the update, `to` and the applied
/// `diff_chunks_against`). That operation is keyed by the pull's [`TransientInstance`], so its /// effects all come from the same settled state (see `diff_chunks_against`). That operation is
/// diff tasks become inactive once the pull's top-level task has finished and can't be re-executed /// keyed by the pull's [`TransientInstance`], so its diff tasks become inactive once the pull's
/// for an old baseline. /// top-level task has finished and can't be re-executed for an old baseline.
pub async fn compute_server_hmr_update( pub async fn compute_server_hmr_update(
chunk_lists: &[ServerHmrChunkList], chunk_lists: &[ServerHmrChunkList],
from: Option<&ServerHmrPullBaseline>, from: Option<&ServerHmrPullBaseline>,
......
...@@ -1977,8 +1977,9 @@ async fn project_server_hmr_snapshot_operation( ...@@ -1977,8 +1977,9 @@ async fn project_server_hmr_snapshot_operation(
} }
/// Snapshot only, keyed by `(project, entry_paths)` and shared by all pulls of these entries. /// Snapshot only, keyed by `(project, entry_paths)` and shared by all pulls of these entries.
/// Diffing happens in [`server_hmr_update_with_effects_operation`], which is keyed per pull, so /// A pull without a baseline reads it directly. Diffing happens in
/// that this shared operation never keeps an old pull baseline active. /// [`server_hmr_update_with_effects_operation`], which is keyed per pull, so that this shared
/// operation never keeps an old pull baseline active.
#[tracing::instrument(level = "info", name = "server hmr snapshot", skip_all)] #[tracing::instrument(level = "info", name = "server hmr snapshot", skip_all)]
#[turbo_tasks::function(operation, root)] #[turbo_tasks::function(operation, root)]
async fn server_hmr_snapshot_with_effects_operation( async fn server_hmr_snapshot_with_effects_operation(
...@@ -2013,8 +2014,8 @@ struct ServerHmrUpdateWithEffects { ...@@ -2013,8 +2014,8 @@ struct ServerHmrUpdateWithEffects {
effects: Arc<Effects>, effects: Arc<Effects>,
} }
/// One server HMR pull: the snapshot (with its effects and issues) and the diff against the /// One server HMR pull with a baseline: the snapshot (with its effects and issues) and the diff
/// pull's baseline, in a single call tree. /// against the pull's baseline, in a single call tree.
/// ///
/// The diff only reads the chunk-list contents of the snapshot. Connecting the snapshot here puts /// The diff only reads the chunk-list contents of the snapshot. Connecting the snapshot here puts
/// their producers into the call tree of this operation, so its strongly consistent read waits /// their producers into the call tree of this operation, so its strongly consistent read waits
...@@ -2023,13 +2024,15 @@ struct ServerHmrUpdateWithEffects { ...@@ -2023,13 +2024,15 @@ struct ServerHmrUpdateWithEffects {
/// ///
/// `from` is a new [`TransientInstance`] per pull, so this operation and its diff tasks are never /// `from` is a new [`TransientInstance`] per pull, so this operation and its diff tasks are never
/// shared with another pull and become inactive once the pull's top-level task has finished; an /// shared with another pull and become inactive once the pull's top-level task has finished; an
/// old baseline is never diffed again. /// old baseline is never diffed again. A pull without a baseline has nothing to diff and reads
/// [`server_hmr_snapshot_with_effects_operation`] directly instead, so it doesn't create a
/// per-pull task (e.g. for every first pull after a restart).
#[tracing::instrument(level = "info", name = "server hmr update", skip_all)] #[tracing::instrument(level = "info", name = "server hmr update", skip_all)]
#[turbo_tasks::function(operation, root)] #[turbo_tasks::function(operation, root)]
async fn server_hmr_update_with_effects_operation( async fn server_hmr_update_with_effects_operation(
project: ResolvedVc<Project>, project: ResolvedVc<Project>,
entry_paths: Vec<RcStr>, entry_paths: Vec<RcStr>,
from: TransientInstance<Option<ServerHmrPullBaseline>>, from: TransientInstance<ServerHmrPullBaseline>,
) -> Result<Vc<ServerHmrUpdateWithEffects>> { ) -> Result<Vc<ServerHmrUpdateWithEffects>> {
let snapshot = server_hmr_snapshot_with_effects_operation(project, entry_paths) let snapshot = server_hmr_snapshot_with_effects_operation(project, entry_paths)
.connect() .connect()
...@@ -2041,7 +2044,7 @@ async fn server_hmr_update_with_effects_operation( ...@@ -2041,7 +2044,7 @@ async fn server_hmr_update_with_effects_operation(
effects, effects,
} = &*snapshot; } = &*snapshot;
let update = let update =
compute_server_hmr_update(chunk_lists.as_slice(), from.as_ref(), version.clone()).await?; compute_server_hmr_update(chunk_lists.as_slice(), Some(&*from), version.clone()).await?;
Ok(ServerHmrUpdateWithEffects { Ok(ServerHmrUpdateWithEffects {
update, update,
issues: issues.clone(), issues: issues.clone(),
...@@ -2088,26 +2091,40 @@ pub async fn project_get_server_hmr_update( ...@@ -2088,26 +2091,40 @@ pub async fn project_get_server_hmr_update(
) -> napi::Result<TurbopackResult<NapiServerHmrUpdate>> { ) -> napi::Result<TurbopackResult<NapiServerHmrUpdate>> {
let container = project.container; let container = project.container;
let turbo_tasks = project.turbopack_ctx.turbo_tasks(); let turbo_tasks = project.turbopack_ctx.turbo_tasks();
let from = TransientInstance::new(from.map(|from| ServerHmrPullBaseline::new(from.0.clone()))); let from = from.map(|from| TransientInstance::new(ServerHmrPullBaseline::new(from.0.clone())));
let read = turbo_tasks let (update, issues) = turbo_tasks
.run(async move { .run(async move {
// HACK(bgw): Remove this unmark call // HACK(bgw): Remove this unmark call
unmark_top_level_task_may_leak_eventually_consistent_state(); unmark_top_level_task_may_leak_eventually_consistent_state();
let project = container.project().to_resolved().await?; let project = container.project().to_resolved().await?;
// HACK(bgw): Remove this mark call // HACK(bgw): Remove this mark call
mark_top_level_task(); mark_top_level_task();
let Some(from) = from else {
// Nothing to diff, so the shared snapshot alone is coherent.
let snapshot_op = server_hmr_snapshot_with_effects_operation(project, entry_paths);
let snapshot =
read_strongly_consistent_and_apply_effects(snapshot_op, |v| &v.effects).await?;
let update = compute_server_hmr_update(
snapshot.chunk_lists.as_slice(),
None,
snapshot.version.clone(),
)
.await?;
return Ok((update, snapshot.issues.clone()));
};
let update_op = server_hmr_update_with_effects_operation(project, entry_paths, from); let update_op = server_hmr_update_with_effects_operation(project, entry_paths, from);
read_strongly_consistent_and_apply_effects(update_op, |v| &v.effects).await let read =
read_strongly_consistent_and_apply_effects(update_op, |v| &v.effects).await?;
Ok((read.update.clone(), read.issues.clone()))
}) })
.await .await
.map_err(|e| napi::Error::from_reason(PrettyPrintError(&e.into()).to_string()))?; .map_err(|e| napi::Error::from_reason(PrettyPrintError(&e.into()).to_string()))?;
Ok(TurbopackResult { Ok(TurbopackResult {
result: NapiServerHmrUpdate::new(&read.update) result: NapiServerHmrUpdate::new(&update)
.map_err(|error| napi::Error::from_reason(PrettyPrintError(&error).to_string()))?, .map_err(|error| napi::Error::from_reason(PrettyPrintError(&error).to_string()))?,
issues: read issues: issues
.issues
.iter() .iter()
.map(|issue| NapiIssue::from(&**issue)) .map(|issue| NapiIssue::from(&**issue))
.collect(), .collect(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment