Skip to content

Commit

Permalink
make node bootstrap asset lazy (#4579)
Browse files Browse the repository at this point in the history
### Description

lazy creation of the chunk group to make walking introspection faster
  • Loading branch information
sokra authored Apr 14, 2023
1 parent 6f7bc5f commit 4b126a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
16 changes: 13 additions & 3 deletions crates/turbopack-node/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use turbo_tasks::primitives::StringVc;
use turbo_tasks_fs::{File, FileSystemPathVc};
use turbopack_core::{
asset::{Asset, AssetContentVc, AssetVc, AssetsVc},
chunk::{ChunkVc, ChunkingContext, ChunkingContextVc, EvaluatableAssetsVc},
ident::AssetIdentVc,
reference::{AssetReferencesVc, SingleAssetReferenceVc},
};
Expand All @@ -13,14 +14,23 @@ use turbopack_ecmascript::utils::StringifyJs;
#[turbo_tasks::value(shared)]
pub(super) struct NodeJsBootstrapAsset {
pub(super) path: FileSystemPathVc,
pub(super) chunks: AssetsVc,
pub(super) chunking_context: ChunkingContextVc,
pub(super) entry: ChunkVc,
pub(super) evaluatable_assets: EvaluatableAssetsVc,
}

#[turbo_tasks::function]
fn node_js_bootstrap_chunk_reference_description() -> StringVc {
StringVc::cell("node.js bootstrap chunk".to_string())
}

impl NodeJsBootstrapAsset {
fn chunks(&self) -> AssetsVc {
self.chunking_context
.evaluated_chunk_group(self.entry, self.evaluatable_assets)
}
}

#[turbo_tasks::value_impl]
impl Asset for NodeJsBootstrapAsset {
#[turbo_tasks::function]
Expand All @@ -36,7 +46,7 @@ impl Asset for NodeJsBootstrapAsset {
// but until then this is a simple hack to make it work for now
let mut output = "Error.stackTraceLimit = 100;\nglobal.self = global;\n".to_string();

for chunk in self.chunks.await?.iter() {
for chunk in self.chunks().await?.iter() {
let path = &*chunk.ident().path().await?;
if let Some(p) = context_path.get_relative_path_to(path) {
if p.ends_with(".js") {
Expand All @@ -50,7 +60,7 @@ impl Asset for NodeJsBootstrapAsset {

#[turbo_tasks::function]
async fn references(&self) -> Result<AssetReferencesVc> {
let chunks = self.chunks.await?;
let chunks = self.chunks().await?;
let mut references = Vec::new();
for chunk in chunks.iter() {
references.push(
Expand Down
7 changes: 3 additions & 4 deletions crates/turbopack-node/src/evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,9 @@ pub async fn get_evaluate_pool(

let bootstrap = NodeJsBootstrapAsset {
path,
chunks: chunking_context.evaluated_chunk_group(
entry_module.as_root_chunk(chunking_context),
runtime_entries.with_entry(entry_module.into()),
),
chunking_context,
entry: entry_module.as_root_chunk(chunking_context),
evaluatable_assets: runtime_entries.with_entry(entry_module.into()),
}
.cell()
.into();
Expand Down
8 changes: 3 additions & 5 deletions crates/turbopack-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,11 @@ pub async fn get_intermediate_asset(
main_entry: EvaluatableAssetVc,
other_entries: EvaluatableAssetsVc,
) -> Result<AssetVc> {
let chunks = chunking_context.evaluated_chunk_group(
main_entry.as_root_chunk(chunking_context),
other_entries.with_entry(main_entry),
);
Ok(NodeJsBootstrapAsset {
path: chunking_context.chunk_path(main_entry.ident(), ".js"),
chunks,
chunking_context,
entry: main_entry.as_root_chunk(chunking_context),
evaluatable_assets: other_entries.with_entry(main_entry),
}
.cell()
.into())
Expand Down

2 comments on commit 4b126a5

@vercel
Copy link

@vercel vercel bot commented on 4b126a5 Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 4b126a5 Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment failed with the following error:

Creating the Deployment Timed Out.

Please sign in to comment.