Skip to content

Commit

Permalink
Sample many modules in benchmarks + reliability fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkirsz committed Nov 17, 2022
1 parent 335de9c commit 3671757
Show file tree
Hide file tree
Showing 13 changed files with 653 additions and 405 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/next-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fs_extra = "1.2.0"
lazy_static = "1.4.0"
once_cell = "1.13.0"
parking_lot = "0.12.1"
rand = "0.8.5"
regex = "1.6.0"
tempfile = "3.3.0"
test-generator = "0.3.0"
Expand Down
16 changes: 10 additions & 6 deletions crates/next-dev/benches/bundlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use self::{
vite::Vite,
webpack::Webpack,
};
use crate::util::env::read_env;

mod nextjs;
mod parcel;
Expand Down Expand Up @@ -59,16 +60,16 @@ pub trait Bundler {
}

pub fn get_bundlers() -> Vec<Box<dyn Bundler>> {
let config = std::env::var("TURBOPACK_BENCH_BUNDLERS").ok();
let config: String = read_env("TURBOPACK_BENCH_BUNDLERS", String::from("turbopack")).unwrap();
let mut turbopack = false;
let mut others = false;
match config.as_deref() {
Some("all") => {
match config.as_ref() {
"all" => {
turbopack = true;
others = true
}
Some("others") => others = true,
None | Some("") => {
"others" => others = true,
"turbopack" => {
turbopack = true;
}
_ => panic!("Invalid value for TURBOPACK_BENCH_BUNDLERS"),
Expand Down Expand Up @@ -129,7 +130,10 @@ pub fn get_bundlers() -> Vec<Box<dyn Bundler>> {
RenderType::ServerSidePrerendered,
)));
bundlers.push(Box::new(Parcel {}));
bundlers.push(Box::new(Vite::new()));
bundlers.push(Box::new(Vite::new(false, false)));
bundlers.push(Box::new(Vite::new(true, false)));
bundlers.push(Box::new(Vite::new(false, true)));
bundlers.push(Box::new(Vite::new(true, true)));
bundlers.push(Box::new(Webpack {}));
}

Expand Down
71 changes: 51 additions & 20 deletions crates/next-dev/benches/bundlers/vite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,81 @@ use crate::{
},
};

pub struct Vite;
pub struct Vite {
swc: bool,
ssr: bool,
}

impl Vite {
pub fn new() -> Self {
Vite {}
pub fn new(swc: bool, ssr: bool) -> Self {
Vite { swc, ssr }
}
}

impl Bundler for Vite {
fn get_name(&self) -> &str {
"Vite CSR"
if self.ssr {
if self.swc {
"Vite SWC SSR"
} else {
"Vite SSR"
}
} else {
if self.swc {
"Vite SWC CSR"
} else {
"Vite CSR"
}
}
}

fn prepare(&self, install_dir: &Path) -> Result<()> {
npm::install(
install_dir,
&[
NpmPackage::new("vite", "^3.2.4"),
NpmPackage::new("@vitejs/plugin-react", "^2.2.0"),
],
)
.context("failed to install from npm")?;
let mut packages = vec![NpmPackage::new("vite", "^3.2.4")];
if self.swc {
packages.push(NpmPackage::new("vite-plugin-swc-react-refresh", "^2.2.1"));
} else {
packages.push(NpmPackage::new("@vitejs/plugin-react", "^2.2.0"));
};
if self.ssr {
packages.push(NpmPackage::new("express", "^4.18.2"));
}
npm::install(install_dir, &packages).context("failed to install from npm")?;

fs::write(
install_dir.join("vite.config.js"),
include_bytes!("vite.config.js"),
if self.swc {
include_bytes!("vite.swc.config.js") as &[u8]
} else {
include_bytes!("vite.config.js") as &[u8]
},
)?;

Ok(())
}

fn start_server(&self, test_dir: &Path) -> Result<(Child, String)> {
let mut proc = Command::new("node")
.args([
(test_dir
let args = if self.ssr {
vec![test_dir
.join("vite-server.mjs")
.to_str()
.unwrap()
.to_string()]
} else {
vec![
test_dir
.join("node_modules")
.join("vite")
.join("bin")
.join("vite.js")
.to_str()
.unwrap()),
"--port",
"0",
])
.unwrap()
.to_string(),
"--port".to_string(),
"0".to_string(),
]
};
let mut proc = Command::new("node")
.args(args)
.env("NO_COLOR", "1")
.current_dir(test_dir)
.stdout(Stdio::piped())
Expand Down
7 changes: 7 additions & 0 deletions crates/next-dev/benches/bundlers/vite/vite.swc.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from "vite";
import { swcReactRefresh } from "vite-plugin-swc-react-refresh";

export default defineConfig({
plugins: [swcReactRefresh()],
esbuild: { jsx: "automatic" },
});
Loading

0 comments on commit 3671757

Please sign in to comment.