Commit d6d16414 authored by Benjamin Woodruff's avatar Benjamin Woodruff

Update next.js callsite for benchmarking

parent 00565bcc
...@@ -5,7 +5,7 @@ use std::{ ...@@ -5,7 +5,7 @@ use std::{
fs::OpenOptions, fs::OpenOptions,
io::{self, BufRead, Write}, io::{self, BufRead, Write},
path::PathBuf, path::PathBuf,
sync::{Arc, Mutex}, sync::{Arc, LazyLock, Mutex},
time::Instant, time::Instant,
}; };
...@@ -14,22 +14,16 @@ use either::Either; ...@@ -14,22 +14,16 @@ use either::Either;
use napi::{JsFunction, threadsafe_function::ThreadsafeFunction}; use napi::{JsFunction, threadsafe_function::ThreadsafeFunction};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use owo_colors::OwoColorize; use owo_colors::OwoColorize;
use serde::Serialize;
use terminal_hyperlink::Hyperlink; use terminal_hyperlink::Hyperlink;
use turbo_tasks::{ use turbo_tasks::{StaticOrArc, TurboTasks, backend::TurboTasksExecutionError};
TurboTasks, TurboTasksApi,
backend::TurboTasksExecutionError,
message_queue::{CompilationEvent, Severity},
};
use turbo_tasks_backend::{ use turbo_tasks_backend::{
BackendOptions, DefaultBackingStorage, GitVersionInfo, NoopBackingStorage, StartupCacheState, BackendOptions, DefaultBackingStorage, NoopBackingStorage, TurboTasksBackend,
TurboTasksBackend, db_invalidation::invalidation_reasons, default_backing_storage,
noop_backing_storage, noop_backing_storage,
}; };
use turbopack_core::error::PrettyPrintError; use turbopack_core::error::PrettyPrintError;
pub type NextTurboTasks = pub type NextTurboTasks =
Arc<TurboTasks<TurboTasksBackend<Either<DefaultBackingStorage, NoopBackingStorage>>>>; StaticOrArc<TurboTasks<TurboTasksBackend<Either<DefaultBackingStorage, NoopBackingStorage>>>>;
/// A value often wrapped in [`napi::bindgen_prelude::External`] that retains the [TurboTasks] /// A value often wrapped in [`napi::bindgen_prelude::External`] that retains the [TurboTasks]
/// instance used by Next.js, and [various napi helpers that are passed to us from /// instance used by Next.js, and [various napi helpers that are passed to us from
...@@ -180,84 +174,30 @@ impl NapiNextTurbopackCallbacks { ...@@ -180,84 +174,30 @@ impl NapiNextTurbopackCallbacks {
} }
pub fn create_turbo_tasks( pub fn create_turbo_tasks(
output_path: PathBuf, _output_path: PathBuf,
persistent_caching: bool, _persistent_caching: bool,
_memory_limit: usize, _memory_limit: usize,
dependency_tracking: bool, dependency_tracking: bool,
is_ci: bool, _is_ci: bool,
is_short_session: bool, _is_short_session: bool,
) -> Result<NextTurboTasks> { ) -> Result<NextTurboTasks> {
Ok(if persistent_caching { static TURBO_TASKS_STATIC: LazyLock<bool> =
let version_info = GitVersionInfo { LazyLock::new(|| std::env::var("NEXT_TURBO_TASKS_STATIC").unwrap() == "1");
describe: env!("VERGEN_GIT_DESCRIBE"), let backend = TurboTasksBackend::new(
dirty: option_env!("CI").is_none_or(|value| value.is_empty()) BackendOptions {
&& env!("VERGEN_GIT_DIRTY") == "true", storage_mode: None,
}; dependency_tracking,
let (backing_storage, cache_state) = default_backing_storage( ..Default::default()
&output_path.join("cache/turbopack"), },
&version_info, Either::Right(noop_backing_storage()),
is_ci, );
is_short_session, if *TURBO_TASKS_STATIC {
)?; Ok(StaticOrArc::Static(TurboTasks::new_static(backend)))
let tt = TurboTasks::new(TurboTasksBackend::new(
BackendOptions {
storage_mode: Some(if std::env::var("TURBO_ENGINE_READ_ONLY").is_ok() {
turbo_tasks_backend::StorageMode::ReadOnly
} else {
turbo_tasks_backend::StorageMode::ReadWrite
}),
dependency_tracking,
num_workers: Some(tokio::runtime::Handle::current().metrics().num_workers()),
..Default::default()
},
Either::Left(backing_storage),
));
if let StartupCacheState::Invalidated { reason_code } = cache_state {
tt.send_compilation_event(Arc::new(StartupCacheInvalidationEvent { reason_code }));
}
tt
} else { } else {
TurboTasks::new(TurboTasksBackend::new( let tt = TurboTasks::new(backend);
BackendOptions { // leak it for apples-to-apples benchmark comparision
storage_mode: None, std::mem::forget(tt.clone());
dependency_tracking, Ok(StaticOrArc::Shared(tt))
..Default::default()
},
Either::Right(noop_backing_storage()),
))
})
}
#[derive(Serialize)]
struct StartupCacheInvalidationEvent {
reason_code: Option<String>,
}
impl CompilationEvent for StartupCacheInvalidationEvent {
fn type_name(&self) -> &'static str {
"StartupCacheInvalidationEvent"
}
fn severity(&self) -> Severity {
Severity::Warning
}
fn message(&self) -> String {
let reason_msg = match self.reason_code.as_deref() {
Some(invalidation_reasons::PANIC) => {
" because we previously detected an internal error in Turbopack"
}
Some(invalidation_reasons::USER_REQUEST) => " as the result of a user request",
_ => "", // ignore unknown reasons
};
format!(
"Turbopack's filesystem cache has been deleted{reason_msg}. Builds or page loads may \
be slower as a result."
)
}
fn to_json(&self) -> String {
serde_json::to_string(self).unwrap()
} }
} }
......
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