Unverified Commit 5c7a4468 authored by Sam Poder's avatar Sam Poder Committed by GitHub

[turbopack] Use experimental chunking heuristics (#95026)

<!-- NEXT_JS_LLM_PR -->
parent be6039d7
...@@ -1602,6 +1602,7 @@ impl Project { ...@@ -1602,6 +1602,7 @@ impl Project {
self: Vc<Self>, self: Vc<Self>,
) -> Result<Vc<Box<dyn ChunkingContext>>> { ) -> Result<Vc<Box<dyn ChunkingContext>>> {
let css_url_suffix = self.next_config().asset_suffix_path(); let css_url_suffix = self.next_config().asset_suffix_path();
let chunking_heuristics = self.next_config().chunking_heuristics().await?;
Ok(get_client_chunking_context(ClientChunkingContextOptions { Ok(get_client_chunking_context(ClientChunkingContextOptions {
mode: self.next_mode(), mode: self.next_mode(),
root_path: self.project_root_path().owned().await?, root_path: self.project_root_path().owned().await?,
...@@ -1632,6 +1633,9 @@ impl Project { ...@@ -1632,6 +1633,9 @@ impl Project {
cross_origin: self.next_config().cross_origin(), cross_origin: self.next_config().cross_origin(),
chunk_loading_global: self.next_config().turbopack_chunk_loading_global(), chunk_loading_global: self.next_config().turbopack_chunk_loading_global(),
style_groups_algorithm: self.next_config().css_chunking().owned().await?, style_groups_algorithm: self.next_config().css_chunking().owned().await?,
chunking_first_page_load_priority: chunking_heuristics.first_page_load_priority,
chunking_priority_boost_percent: chunking_heuristics.priority_boost_percent,
chunking_request_cost: chunking_heuristics.request_cost,
})) }))
} }
......
...@@ -482,6 +482,9 @@ pub struct ClientChunkingContextOptions { ...@@ -482,6 +482,9 @@ pub struct ClientChunkingContextOptions {
pub cross_origin: Vc<CrossOrigin>, pub cross_origin: Vc<CrossOrigin>,
pub chunk_loading_global: Vc<Option<RcStr>>, pub chunk_loading_global: Vc<Option<RcStr>>,
pub style_groups_algorithm: StyleGroupsAlgorithm, pub style_groups_algorithm: StyleGroupsAlgorithm,
pub chunking_first_page_load_priority: Option<u32>,
pub chunking_priority_boost_percent: Option<u32>,
pub chunking_request_cost: Option<u64>,
} }
/// Next.js' chunk-load retry policy for the Turbopack browser runtime. /// Next.js' chunk-load retry policy for the Turbopack browser runtime.
...@@ -520,6 +523,9 @@ pub async fn get_client_chunking_context( ...@@ -520,6 +523,9 @@ pub async fn get_client_chunking_context(
cross_origin, cross_origin,
chunk_loading_global, chunk_loading_global,
style_groups_algorithm, style_groups_algorithm,
chunking_first_page_load_priority,
chunking_priority_boost_percent,
chunking_request_cost,
} = options; } = options;
let next_mode = mode.await?; let next_mode = mode.await?;
...@@ -584,6 +590,9 @@ pub async fn get_client_chunking_context( ...@@ -584,6 +590,9 @@ pub async fn get_client_chunking_context(
min_chunk_size: 50_000, min_chunk_size: 50_000,
max_chunk_count_per_group: 40, max_chunk_count_per_group: 40,
max_merge_chunk_size: 200_000, max_merge_chunk_size: 200_000,
first_page_load_priority: chunking_first_page_load_priority,
priority_boost_percent: chunking_priority_boost_percent,
request_cost: chunking_request_cost,
..Default::default() ..Default::default()
}, },
) )
......
...@@ -260,6 +260,18 @@ pub struct ChunkingConfig { ...@@ -260,6 +260,18 @@ pub struct ChunkingConfig {
/// type. /// type.
pub style_groups_algorithm: StyleGroupsAlgorithm, pub style_groups_algorithm: StyleGroupsAlgorithm,
/// First-page-load priority as an integer percentage (`0..=100`), or `None` to use the
/// default. Used by the production chunker's merge heuristics.
pub first_page_load_priority: Option<u32>,
/// Priority boost as an integer percentage (e.g. `150` for a 1.5x boost), or `None` to use the
/// default. Used by the production chunker's merge heuristics.
pub priority_boost_percent: Option<u32>,
/// Estimated request cost in bytes, or `None` to use the default. Used by the production
/// chunker's merge heuristics.
pub request_cost: Option<u64>,
#[allow(dead_code)] #[allow(dead_code)]
pub placeholder_for_future_extensions: (), pub placeholder_for_future_extensions: (),
} }
......
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