Skip to content

Commit 184ec1c

Browse files
authored
[Turbopack] no need to depend on write completion (#69660)
### What The node.js pool doesn't need to be invalidated when pool code is re-writting. It's enough to invalidate it when the pool code has changed. Avoid having transient tasks in the embedded filesystem. It's not allow to have persistent tasks depend on transient tasks with Persistent Caching. Avoid triggering invalidation when State is dropped. State might be dropped after serialization when it's stored in persistent cache. This doesn't mean we want to invalidate the tasks
1 parent 4c0728d commit 184ec1c

File tree

6 files changed

+33
-57
lines changed

6 files changed

+33
-57
lines changed

crates/next-api/src/project.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ impl Project {
11111111
pub async fn emit_all_output_assets(
11121112
self: Vc<Self>,
11131113
output_assets: Vc<OutputAssetsOperation>,
1114-
) -> Result<Vc<Completion>> {
1114+
) -> Result<Vc<()>> {
11151115
let span = tracing::info_span!("emitting");
11161116
async move {
11171117
let all_output_assets = all_assets_from_entries_operation(output_assets);
@@ -1120,21 +1120,27 @@ impl Project {
11201120
let node_root = self.node_root();
11211121

11221122
if let Some(map) = self.await?.versioned_content_map {
1123-
let completion = map.insert_output_assets(
1124-
all_output_assets,
1125-
node_root,
1126-
client_relative_path,
1127-
node_root,
1128-
);
1129-
1130-
Ok(completion)
1123+
let _ = map
1124+
.insert_output_assets(
1125+
all_output_assets,
1126+
node_root,
1127+
client_relative_path,
1128+
node_root,
1129+
)
1130+
.resolve()
1131+
.await?;
1132+
1133+
Ok(Vc::cell(()))
11311134
} else {
1132-
Ok(emit_assets(
1135+
let _ = emit_assets(
11331136
*all_output_assets.await?,
11341137
node_root,
11351138
client_relative_path,
11361139
node_root,
1137-
))
1140+
)
1141+
.resolve()
1142+
.await?;
1143+
Ok(Vc::cell(()))
11381144
}
11391145
}
11401146
.instrument(span)

turbopack/crates/turbo-tasks-fs/src/embed/dir.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub use ::include_dir::{
22
include_dir, {self},
33
};
44
use anyhow::Result;
5-
use turbo_tasks::{RcStr, TransientInstance, Vc};
5+
use turbo_tasks::{RcStr, Vc};
66

77
use crate::{embed::EmbeddedFileSystem, DiskFileSystem, FileSystem};
88

@@ -17,12 +17,11 @@ pub async fn directory_from_relative_path(
1717
Ok(Vc::upcast(disk_fs))
1818
}
1919

20-
#[turbo_tasks::function]
21-
pub async fn directory_from_include_dir(
20+
pub fn directory_from_include_dir(
2221
name: RcStr,
23-
dir: TransientInstance<&'static include_dir::Dir<'static>>,
24-
) -> Result<Vc<Box<dyn FileSystem>>> {
25-
Ok(Vc::upcast(EmbeddedFileSystem::new(name, dir)))
22+
dir: &'static include_dir::Dir<'static>,
23+
) -> Vc<Box<dyn FileSystem>> {
24+
Vc::upcast(EmbeddedFileSystem::new(name, dir))
2625
}
2726

2827
/// Returns an embedded [Vc<Box<dyn FileSystem>>] for the given path.
@@ -71,9 +70,6 @@ macro_rules! embed_directory_internal {
7170

7271
static dir: include_dir::Dir<'static> = turbo_tasks_fs::embed::include_dir!($path);
7372

74-
turbo_tasks_fs::embed::directory_from_include_dir(
75-
$name.into(),
76-
turbo_tasks::TransientInstance::new(&dir),
77-
)
73+
turbo_tasks_fs::embed::directory_from_include_dir($name.into(), &dir)
7874
}};
7975
}

turbopack/crates/turbo-tasks-fs/src/embed/fs.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
use anyhow::{bail, Result};
22
use include_dir::{Dir, DirEntry};
3-
use turbo_tasks::{Completion, RcStr, TransientInstance, ValueToString, Vc};
3+
use turbo_tasks::{Completion, RcStr, ValueToString, Vc};
44

55
use crate::{
66
DirectoryContent, DirectoryEntry, File, FileContent, FileMeta, FileSystem, FileSystemPath,
77
LinkContent,
88
};
99

10-
#[turbo_tasks::value(serialization = "none")]
10+
#[turbo_tasks::value(serialization = "none", cell = "new", eq = "manual")]
1111
pub struct EmbeddedFileSystem {
1212
name: RcStr,
1313
#[turbo_tasks(trace_ignore)]
14-
dir: TransientInstance<&'static Dir<'static>>,
14+
dir: &'static Dir<'static>,
1515
}
1616

17-
#[turbo_tasks::value_impl]
1817
impl EmbeddedFileSystem {
19-
#[turbo_tasks::function]
20-
pub(super) fn new(
21-
name: RcStr,
22-
dir: TransientInstance<&'static Dir<'static>>,
23-
) -> Vc<EmbeddedFileSystem> {
18+
pub(super) fn new(name: RcStr, dir: &'static Dir<'static>) -> Vc<EmbeddedFileSystem> {
2419
EmbeddedFileSystem { name, dir }.cell()
2520
}
2621
}
@@ -46,7 +41,7 @@ impl FileSystem for EmbeddedFileSystem {
4641
async fn read_dir(&self, path: Vc<FileSystemPath>) -> Result<Vc<DirectoryContent>> {
4742
let path_str = &path.await?.path;
4843
let dir = match (path_str.as_str(), self.dir.get_dir(path_str)) {
49-
("", _) => *self.dir,
44+
("", _) => self.dir,
5045
(_, Some(dir)) => dir,
5146
(_, None) => return Ok(DirectoryContent::NotFound.cell()),
5247
};

turbopack/crates/turbo-tasks-fs/src/invalidator_map.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,3 @@ impl<'de> Deserialize<'de> for InvalidatorMap {
7171
deserializer.deserialize_newtype_struct("InvalidatorMap", V)
7272
}
7373
}
74-
75-
impl Drop for InvalidatorMap {
76-
fn drop(&mut self) {
77-
while let Ok((_, value)) = self.queue.pop() {
78-
value.invalidate();
79-
}
80-
for (_, invalidators) in self.map.lock().unwrap().drain() {
81-
for invalidator in invalidators {
82-
invalidator.invalidate();
83-
}
84-
}
85-
}
86-
}

turbopack/crates/turbo-tasks/src/state.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,6 @@ impl<'de, T> Deserialize<'de> for State<T> {
6868
}
6969
}
7070

71-
impl<T> Drop for State<T> {
72-
fn drop(&mut self) {
73-
let mut inner = self.inner.lock();
74-
for invalidator in take(&mut inner.invalidators) {
75-
invalidator.invalidate();
76-
}
77-
}
78-
}
79-
8071
impl<T> State<T> {
8172
pub fn new(value: T) -> Self {
8273
mark_stateful();

turbopack/crates/turbopack-node/src/evaluate.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use turbo_tasks_env::ProcessEnv;
2121
use turbo_tasks_fs::{to_sys_path, File, FileSystemPath};
2222
use turbopack_core::{
2323
asset::AssetContent,
24+
changed::content_changed,
2425
chunk::{ChunkingContext, ChunkingContextExt, EvaluatableAsset, EvaluatableAssets},
2526
context::AssetContext,
2627
error::PrettyPrintError,
@@ -153,11 +154,11 @@ pub async fn get_evaluate_pool(
153154
chunking_context.root_entry_chunk_group_asset(path, entry_module, runtime_entries);
154155

155156
let output_root: Vc<FileSystemPath> = chunking_context.output_root();
156-
let emit_package = emit_package_json(output_root);
157-
let emit = emit(bootstrap, output_root);
157+
let _ = emit_package_json(output_root);
158+
// Invalidate pool when code content changes
159+
content_changed(Vc::upcast(bootstrap)).await?;
160+
let _ = emit(bootstrap, output_root);
158161
let assets_for_source_mapping = internal_assets_for_source_mapping(bootstrap, output_root);
159-
emit_package.await?;
160-
emit.await?;
161162
let pool = NodeJsPool::new(
162163
cwd,
163164
entrypoint,

0 commit comments

Comments
 (0)