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
d6d16414
Commit
d6d16414
authored
Oct 21, 2025
by
Benjamin Woodruff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update next.js callsite for benchmarking
parent
00565bcc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
84 deletions
+24
-84
turbopack_ctx.rs
crates/napi/src/next_api/turbopack_ctx.rs
+24
-84
No files found.
crates/napi/src/next_api/turbopack_ctx.rs
View file @
d6d16414
...
...
@@ -5,7 +5,7 @@ use std::{
fs
::
OpenOptions
,
io
::{
self
,
BufRead
,
Write
},
path
::
PathBuf
,
sync
::{
Arc
,
Mutex
},
sync
::{
Arc
,
LazyLock
,
Mutex
},
time
::
Instant
,
};
...
...
@@ -14,22 +14,16 @@ use either::Either;
use
napi
::{
JsFunction
,
threadsafe_function
::
ThreadsafeFunction
};
use
once_cell
::
sync
::
Lazy
;
use
owo_colors
::
OwoColorize
;
use
serde
::
Serialize
;
use
terminal_hyperlink
::
Hyperlink
;
use
turbo_tasks
::{
TurboTasks
,
TurboTasksApi
,
backend
::
TurboTasksExecutionError
,
message_queue
::{
CompilationEvent
,
Severity
},
};
use
turbo_tasks
::{
StaticOrArc
,
TurboTasks
,
backend
::
TurboTasksExecutionError
};
use
turbo_tasks_backend
::{
BackendOptions
,
DefaultBackingStorage
,
GitVersionInfo
,
NoopBackingStorage
,
StartupCacheState
,
TurboTasksBackend
,
db_invalidation
::
invalidation_reasons
,
default_backing_storage
,
BackendOptions
,
DefaultBackingStorage
,
NoopBackingStorage
,
TurboTasksBackend
,
noop_backing_storage
,
};
use
turbopack_core
::
error
::
PrettyPrintError
;
pub
type
NextTurboTasks
=
Arc
<
TurboTasks
<
TurboTasksBackend
<
Either
<
DefaultBackingStorage
,
NoopBackingStorage
>>>>
;
StaticOr
Arc
<
TurboTasks
<
TurboTasksBackend
<
Either
<
DefaultBackingStorage
,
NoopBackingStorage
>>>>
;
/// 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
...
...
@@ -180,84 +174,30 @@ impl NapiNextTurbopackCallbacks {
}
pub
fn
create_turbo_tasks
(
output_path
:
PathBuf
,
persistent_caching
:
bool
,
_
output_path
:
PathBuf
,
_
persistent_caching
:
bool
,
_memory_limit
:
usize
,
dependency_tracking
:
bool
,
is_ci
:
bool
,
is_short_session
:
bool
,
_
is_ci
:
bool
,
_
is_short_session
:
bool
,
)
->
Result
<
NextTurboTasks
>
{
Ok
(
if
persistent_caching
{
let
version_info
=
GitVersionInfo
{
describe
:
env!
(
"VERGEN_GIT_DESCRIBE"
),
dirty
:
option_env!
(
"CI"
)
.is_none_or
(|
value
|
value
.is_empty
())
&&
env!
(
"VERGEN_GIT_DIRTY"
)
==
"true"
,
};
let
(
backing_storage
,
cache_state
)
=
default_backing_storage
(
&
output_path
.join
(
"cache/turbopack"
),
&
version_info
,
is_ci
,
is_short_session
,
)
?
;
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
static
TURBO_TASKS_STATIC
:
LazyLock
<
bool
>
=
LazyLock
::
new
(||
std
::
env
::
var
(
"NEXT_TURBO_TASKS_STATIC"
)
.unwrap
()
==
"1"
);
let
backend
=
TurboTasksBackend
::
new
(
BackendOptions
{
storage_mode
:
None
,
dependency_tracking
,
..
Default
::
default
()
},
Either
::
Right
(
noop_backing_storage
()),
);
if
*
TURBO_TASKS_STATIC
{
Ok
(
StaticOrArc
::
Static
(
TurboTasks
::
new_static
(
backend
)))
}
else
{
TurboTasks
::
new
(
TurboTasksBackend
::
new
(
BackendOptions
{
storage_mode
:
None
,
dependency_tracking
,
..
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
()
let
tt
=
TurboTasks
::
new
(
backend
);
// leak it for apples-to-apples benchmark comparision
std
::
mem
::
forget
(
tt
.clone
());
Ok
(
StaticOrArc
::
Shared
(
tt
))
}
}
...
...
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