Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion turbopack/crates/turbopack-nodejs/src/ecmascript/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
pub(crate) mod node;
pub mod node;

pub use node::{
EcmascriptBuildNodeChunk, EcmascriptBuildNodeEntryChunk, EcmascriptBuildNodeRuntimeChunk,
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::NodeJsChunkingContext;
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("Ecmascript Build Node Chunk")]
pub(crate) struct EcmascriptBuildNodeChunk {
pub struct EcmascriptBuildNodeChunk {
chunking_context: ResolvedVc<NodeJsChunkingContext>,
chunk: ResolvedVc<EcmascriptChunk>,
}
Expand Down Expand Up @@ -66,6 +66,11 @@ impl EcmascriptBuildNodeChunk {
self.source_map(),
))
}

#[turbo_tasks::function]
pub fn chunk(&self) -> Vc<Box<dyn Chunk>> {
Vc::upcast(*self.chunk)
}
Comment on lines +70 to +73
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The chunk method is a simple accessor that performs a cheap Vc::upcast. Marking it as a #[turbo_tasks::function] adds unnecessary overhead to the task graph (scheduling, memoization, etc.). It is better to provide it as a regular public method.

    pub fn chunk(&self) -> Vc<Box<dyn Chunk>> {
        Vc::upcast(*self.chunk)
    }

}

#[turbo_tasks::value_impl]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use turbo_tasks::{ResolvedVc, ValueToString, Vc, turbobail};
use turbo_tasks_fs::{File, FileContent, FileSystemPath};
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{ChunkingContext, EvaluatableAssets, ModuleChunkItemIdExt},
chunk::{ChunkData, ChunkingContext, ChunksData, EvaluatableAssets, ModuleChunkItemIdExt},
Comment thread
fireairforce marked this conversation as resolved.
code_builder::{Code, CodeBuilder},
module_graph::ModuleGraph,
output::{
Expand All @@ -25,7 +25,7 @@ use crate::NodeJsChunkingContext;
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("Ecmascript Build Node Entry Chunk")]
pub(crate) struct EcmascriptBuildNodeEntryChunk {
pub struct EcmascriptBuildNodeEntryChunk {
path: FileSystemPath,
other_chunks: ResolvedVc<OutputAssets>,
evaluatable_assets: ResolvedVc<EvaluatableAssets>,
Expand Down Expand Up @@ -63,6 +63,29 @@ impl EcmascriptBuildNodeEntryChunk {
.cell()
}

#[turbo_tasks::function]
pub async fn chunks_data(&self) -> Result<Vc<ChunksData>> {
Ok(ChunkData::from_assets(
self.chunking_context.output_root().owned().await?,
*self.other_chunks,
))
}
Comment on lines +66 to +72
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The chunks_data implementation can be simplified. ChunkData::from_assets accepts Vc arguments, so there is no need to await the output root or use .owned(). Removing the async and Result reduces overhead and aligns with the implementation in EcmascriptBrowserEvaluateChunk.

    #[turbo_tasks::function]
    pub fn chunks_data(&self) -> Vc<ChunksData> {
        ChunkData::from_assets(self.chunking_context.output_root(), *self.other_chunks)
    }


#[turbo_tasks::function]
pub fn evaluatable_assets(&self) -> Vc<EvaluatableAssets> {
*self.evaluatable_assets
}
Comment on lines +74 to +77
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This is a simple field accessor. Using #[turbo_tasks::function] here is unnecessary and adds overhead to the task graph. It should be a regular public method.

    pub fn evaluatable_assets(&self) -> Vc<EvaluatableAssets> {
        *self.evaluatable_assets
    }


#[turbo_tasks::function]
pub fn module_graph(&self) -> Vc<ModuleGraph> {
*self.module_graph
}
Comment on lines +79 to +82
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This is a simple field accessor. Using #[turbo_tasks::function] here is unnecessary and adds overhead to the task graph. It should be a regular public method.

    pub fn module_graph(&self) -> Vc<ModuleGraph> {
        *self.module_graph
    }


#[turbo_tasks::function]
pub fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
Vc::upcast(*self.chunking_context)
}
Comment on lines +84 to +87
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This method performs a simple field access and a cheap Vc::upcast. Using #[turbo_tasks::function] here is unnecessary and adds overhead to the task graph. It should be a regular public method.

    pub fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
        Vc::upcast(*self.chunking_context)
    }


#[turbo_tasks::function]
async fn code(self: Vc<Self>) -> Result<Vc<Code>> {
let this = self.await?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub(crate) mod chunk;
pub(crate) mod runtime;
pub mod chunk;
pub mod runtime;
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::NodeJsChunkingContext;
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("Ecmascript Build Node Runtime Chunk")]
pub(crate) struct EcmascriptBuildNodeRuntimeChunk {
pub struct EcmascriptBuildNodeRuntimeChunk {
chunking_context: ResolvedVc<NodeJsChunkingContext>,
}

Expand Down
7 changes: 5 additions & 2 deletions turbopack/crates/turbopack-nodejs/src/ecmascript/node/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pub(crate) mod chunk;
pub mod chunk;
pub(crate) mod content;
pub(crate) mod entry;
pub mod entry;
pub(crate) mod update;
pub(crate) mod version;

pub use chunk::EcmascriptBuildNodeChunk;
pub use entry::{chunk::EcmascriptBuildNodeEntryChunk, runtime::EcmascriptBuildNodeRuntimeChunk};
5 changes: 4 additions & 1 deletion turbopack/crates/turbopack-nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#![feature(arbitrary_self_types_pointers)]

pub(crate) mod chunking_context;
pub(crate) mod ecmascript;
pub mod ecmascript;

pub use chunking_context::{NodeJsChunkingContext, NodeJsChunkingContextBuilder};
pub use ecmascript::{
EcmascriptBuildNodeChunk, EcmascriptBuildNodeEntryChunk, EcmascriptBuildNodeRuntimeChunk,
};
Loading