Skip to content

Commit

Permalink
Turbopack: Fix Next.js in cross-bundler benchmarks
Browse files Browse the repository at this point in the history
This:

- Drops Next.js 11 from cross-bundler benchmarks
- Adds Next.js 14 to cross-bundler benchmarks
- Uses support for port `0` to bind to a free port in Next.js 13+
  • Loading branch information
wbinnssmith committed Feb 2, 2024
1 parent 9f0048a commit a54c600
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 25 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/bench-turbopack-scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ jobs:
TURBOPACK_BENCH_COUNTS: 100,500,1000
TURBOPACK_BENCH_BUNDLERS: all

# This measures Next.js 14
- name: next 14
title: Next.js 14
run_args: '"(Turbopack SSR/1000|Next.js 14)"'
TURBOPACK_BENCH_COUNTS: 100,500,1000
TURBOPACK_BENCH_BUNDLERS: all

# This measures Next.js 13
- name: next 13
title: Next.js 13
Expand All @@ -54,13 +61,6 @@ jobs:
TURBOPACK_BENCH_COUNTS: 100,500,1000
TURBOPACK_BENCH_BUNDLERS: all

# This measures Next.js 11
- name: next 11
title: Next.js 11
run_args: '"(Turbopack SSR/1000|Next.js 11)"'
TURBOPACK_BENCH_COUNTS: 100,500,1000
TURBOPACK_BENCH_BUNDLERS: all

# This measures Vite
- name: vite
title: Vite
Expand Down
50 changes: 39 additions & 11 deletions crates/turbopack-bench/src/bundlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@ pub fn get_bundlers() -> Vec<Box<dyn Bundler>> {
true,
RenderType::ServerSideRenderedWithEvents,
)),
Box::new(NextJs::new(
NextJsVersion::V14,
"Next.js 14 Turbo SSR",
"/page",
true,
RenderType::ServerSidePrerendered,
)),
Box::new(NextJs::new(
NextJsVersion::V14,
"Next.js 14 Turbo RSC",
"/app",
true,
RenderType::ServerSideRenderedWithEvents,
)),
Box::new(NextJs::new(
NextJsVersion::V14,
"Next.js 14 Turbo RCC",
"/client",
true,
RenderType::ServerSidePrerendered,
)),
Box::new(NextJs::new(
NextJsVersion::V13,
"Next.js 13 Turbo SSR",
Expand Down Expand Up @@ -138,37 +159,44 @@ pub fn get_bundlers() -> Vec<Box<dyn Bundler>> {
RenderType::ServerSideRenderedWithEvents,
)),
Box::new(NextJs::new(
NextJsVersion::V13,
"Next.js 13 webpack SSR",
NextJsVersion::V14,
"Next.js 14 webpack SSR",
"/page",
false,
RenderType::ServerSidePrerendered,
)),
Box::new(NextJs::new(
NextJsVersion::V13,
"Next.js 13 webpack RSC",
NextJsVersion::V14,
"Next.js 14 webpack RSC",
"/app",
false,
RenderType::ServerSideRenderedWithEvents,
)),
Box::new(NextJs::new(
NextJsVersion::V13,
"Next.js 13 webpack RCC",
NextJsVersion::V14,
"Next.js 14 webpack RCC",
"/client",
false,
RenderType::ServerSidePrerendered,
)),
Box::new(NextJs::new(
NextJsVersion::V12,
"Next.js 12 webpack SSR",
NextJsVersion::V13,
"Next.js 13 webpack SSR",
"/page",
false,
RenderType::ServerSidePrerendered,
)),
Box::new(NextJs::new(
NextJsVersion::V11,
"Next.js 11 webpack SSR",
"/page",
NextJsVersion::V13,
"Next.js 13 webpack RSC",
"/app",
false,
RenderType::ServerSideRenderedWithEvents,
)),
Box::new(NextJs::new(
NextJsVersion::V13,
"Next.js 13 webpack RCC",
"/client",
false,
RenderType::ServerSidePrerendered,
)),
Expand Down
22 changes: 15 additions & 7 deletions crates/turbopack-bench/src/bundlers/nextjs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use crate::{

#[derive(Debug)]
pub enum NextJsVersion {
V11,
V12,
V13,
V14,
Canary,
}

Expand Down Expand Up @@ -102,11 +102,16 @@ impl Bundler for NextJs {
.unwrap(),
"dev",
"--port",
// Next.js currently has a bug where requests for port 0 are ignored and it falls
// back to the default 3000. Use portpicker instead.
&portpicker::pick_unused_port()
.ok_or_else(|| anyhow!("failed to pick unused port"))?
.to_string(),
&match self.version {
NextJsVersion::V12 => {
// Next.js 12 has a bug where requests for port 0 are ignored and it falls
// back to the default 3000. Use portpicker instead.
portpicker::pick_unused_port()
.ok_or_else(|| anyhow!("failed to pick unused port"))?
}
_ => 0,
}
.to_string(),
])
.current_dir(test_dir)
.stdout(Stdio::piped())
Expand All @@ -120,7 +125,10 @@ impl Bundler for NextJs {
proc.stdout
.as_mut()
.ok_or_else(|| anyhow!("missing stdout"))?,
Regex::new("started server.*url: (.*)")?,
match self.version {
NextJsVersion::V12 => Regex::new("started server.*url: (.*)"),
_ => Regex::new("- Local:\\s+(.*)"),
}?,
)
.ok_or_else(|| anyhow!("failed to find devserver address"))?;

Expand Down

0 comments on commit a54c600

Please sign in to comment.