Skip to content

Commit

Permalink
test(benchmark): add modules_10000 bench case (#9279)
Browse files Browse the repository at this point in the history
* test(benchmark): add modules_10000 bench case

* chore: lint

* chore: update

* fix: try

* chore: lint
  • Loading branch information
h-a-n-a authored Feb 14, 2025
1 parent cae75b7 commit aa7326b
Show file tree
Hide file tree
Showing 10,012 changed files with 168,250 additions and 10 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"packages/rspack-test-tools/tests/**/*",
"packages/rspack-test-tools/src/helper/legacy/**/*",
"tests/e2e/**/*",
"tasks/benchmark/benches/**/*",
// --- ignore runtime code in browser
"packages/rspack/hot",
"packages/rspack/src/runtime/moduleFederationDefaultRuntime.js"
Expand Down Expand Up @@ -63,6 +64,7 @@
"packages/rspack-test-tools/template",
"packages/rspack-test-tools/src/helper/legacy/**/*",
"packages/rspack/module.d.ts",
"tasks/benchmark/benches/**/*",
// --- ignore runtime code in browser
"packages/rspack/hot",
"packages/rspack/src/runtime/moduleFederationDefaultRuntime.js"
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ packages:
- "tests/plugin-test"
- "tests/webpack-cli-test"
- "tests/bench"
- "tasks/benchmark/benches/**"
# this following is used to test resolve in monorepo
- "packages/rspack-test-tools/tests/normalCases/resolve/pnpm-workspace/packages/*"
18 changes: 9 additions & 9 deletions tasks/benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ description = "rspack benchmark tooling"
edition = "2021"
license = "MIT"
name = "rspack_benchmark"
publish = false
repository = "https://github.com/web-infra-dev/rspack"
version = "0.2.0"
publish = false

[features]
default = []
codspeed = ["criterion2/codspeed"]

[dependencies]
criterion2 = { default-features = false, version = "2.0.0", features = ["async_tokio"]}
rspack = { workspace = true }
rspack_fs = { workspace = true }
rspack_core = { workspace = true }
tokio = { workspace = true }
serde_json = { workspace = true }
criterion2 = { default-features = false, version = "2.0.0", features = ["async_tokio"] }
rspack = { workspace = true, features = ["full"] }
rspack_core = { workspace = true }
rspack_fs = { workspace = true }
rspack_regex = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }

[[bench]]
name = "benches"
harness = false
name = "benches"
4 changes: 3 additions & 1 deletion tasks/benchmark/benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
use basic::basic;
use build_chunk_graph::chunk_graph;
use criterion::criterion_main;
use modules_10000::modules_10000;

mod basic;
mod build_chunk_graph;
mod modules_10000;

criterion_main!(basic, chunk_graph);
criterion_main!(basic, chunk_graph, modules_10000);
102 changes: 102 additions & 0 deletions tasks/benchmark/benches/modules_10000.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#![feature(trait_upcasting)]
#![allow(unused_attributes)]
#![allow(clippy::unwrap_used)]

use std::{path::PathBuf, sync::Arc};

use criterion::criterion_group;
use rspack::builder::Builder as _;
use rspack_benchmark::Criterion;
use rspack_core::{
Compiler, Experiments, Mode, ModuleOptions, ModuleRule, ModuleRuleEffect, ModuleRuleUse,
ModuleRuleUseLoader, Resolve, RuleSetCondition,
};
use rspack_fs::{MemoryFileSystem, NativeFileSystem};
use rspack_regex::RspackRegex;
use serde_json::json;
use tokio::runtime::Builder;

async fn basic_compile(production: bool) {
let dir = std::env::var("CARGO_MANIFEST_DIR")
.map(PathBuf::from)
.or(
// This is a workaround for the issue where the CARGO_MANIFEST_DIR is not set in the test environment
std::env::var("CODSPEED_CARGO_WORKSPACE_ROOT")
.map(|workspace_root| PathBuf::from(workspace_root).join("tasks/benchmark")),
)
.unwrap()
.join("benches/modules_10000");

let mut builder = Compiler::builder();
builder
.context(dir.to_string_lossy().to_string())
.entry("main", "./index.jsx")
.module(ModuleOptions::builder().rule(ModuleRule {
test: Some(RuleSetCondition::Regexp(
RspackRegex::new("\\.(j|t)s(x)?$").unwrap(),
)),
effect: ModuleRuleEffect {
r#use: ModuleRuleUse::Array(vec![ModuleRuleUseLoader {
loader: "builtin:swc-loader".to_string(),
options: Some(json!({
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
},
"transform": {
"react": {
"runtime": "automatic",
},
},
"externalHelpers": true,
},
"env": {
"targets": "Chrome >= 48"
}
}).to_string()),
}]),
..Default::default()
},
..Default::default()
}))
.cache(rspack_core::CacheOptions::Disabled)
.resolve(Resolve {
extensions: Some(vec!["...".to_string(), ".jsx".to_string()]),
..Default::default()
})
.experiments(Experiments::builder().css(true))
.input_filesystem(Arc::new(NativeFileSystem::new(false)))
.output_filesystem(Arc::new(MemoryFileSystem::default()))
.enable_loader_swc();

if production {
builder.mode(Mode::Production);
} else {
builder.mode(Mode::Development);
}

let mut compiler = builder.build();

compiler.run().await.unwrap();

assert!(compiler
.compilation
.get_errors()
.collect::<Vec<_>>()
.is_empty());
}

pub fn modules_10000_benchmark(c: &mut Criterion) {
let rt = Builder::new_multi_thread().build().unwrap();

c.bench_function("10000_production", |b| {
b.to_async(&rt).iter(|| basic_compile(true));
});

c.bench_function("10000_development", |b| {
b.to_async(&rt).iter(|| basic_compile(false));
});
}

criterion_group!(modules_10000, modules_10000_benchmark);
11 changes: 11 additions & 0 deletions tasks/benchmark/benches/modules_10000/hmr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = [
{
rebuildChangeFile: "./src/f0.jsx",
generateContent: function (originalContent, runTimes) {
return (
`import "data:text/javascript,export default ${runTimes}";
` + originalContent
);
}
}
];
12 changes: 12 additions & 0 deletions tasks/benchmark/benches/modules_10000/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>10000</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
13 changes: 13 additions & 0 deletions tasks/benchmark/benches/modules_10000/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import React, { useEffect } from "react";
import ReactDom from "react-dom/client";
import App1 from "./src/f0";

ReactDom.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<App1 />
</React.StrictMode>
);



7 changes: 7 additions & 0 deletions tasks/benchmark/benches/modules_10000/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "10000",
"dependencies": {
"react": "^19.0.0",
"react-dom": "^19.0.0"
}
}
74 changes: 74 additions & 0 deletions tasks/benchmark/benches/modules_10000/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const path = require("path");
const rspack = require("@rspack/core");
const ReactRefreshPlugin = require("@rspack/plugin-react-refresh");

const prod = process.env.NODE_ENV === "production";
/** @type {import("@rspack/cli").Configuration} */
module.exports = {
resolve: {
extensions: [".js", ".jsx"]
},
entry: { main: "./index.jsx" },
plugins: [
new rspack.HtmlRspackPlugin({
template: path.resolve(__dirname, "./index.html")
}),
!prod && new ReactRefreshPlugin()
].filter(Boolean),
module: {
rules: [
{
test: /\.(j|t)s$/,
exclude: [/[\\/]node_modules[\\/]/],
loader: "builtin:swc-loader",
options: {
sourceMap: true,
jsc: {
parser: {
syntax: "typescript"
},
externalHelpers: true
},
env: {
targets: "Chrome >= 48"
}
}
},
{
test: /\.(j|t)sx$/,
loader: "builtin:swc-loader",
exclude: [/[\\/]node_modules[\\/]/],
options: {
sourceMap: true,
jsc: {
parser: {
syntax: "typescript",
tsx: true
},
transform: {
react: {
runtime: "automatic",
development: !prod,
refresh: !prod
}
},
externalHelpers: true
},
env: {
targets: "Chrome >= 48"
}
}
}
]
},
optimization: {
splitChunks: {
chunks: "all",
cacheGroups: {
d1: {
test: /\/d1\//
}
}
}
}
};
21 changes: 21 additions & 0 deletions tasks/benchmark/benches/modules_10000/src/d0/d0/d0/d0/f0.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@


import React, {useEffect} from 'react'
import Icon from '@icon-park/react/es/all';


function Navbar({ show }) {
useEffect(() => {
console.log(Date.now());
})
return (
<div>
<span> 19 </span>
{Date.now()}
</div>
)
}

export default Navbar


15 changes: 15 additions & 0 deletions tasks/benchmark/benches/modules_10000/src/d0/d0/d0/d0/f1.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import React from 'react'
import Icon from '@icon-park/react/es/all';


function Navbar({ show }) {
return (
<div>

</div>
)
}

export default Navbar

15 changes: 15 additions & 0 deletions tasks/benchmark/benches/modules_10000/src/d0/d0/d0/d0/f2.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import React from 'react'
import Icon from '@icon-park/react/es/all';


function Navbar({ show }) {
return (
<div>

</div>
)
}

export default Navbar

15 changes: 15 additions & 0 deletions tasks/benchmark/benches/modules_10000/src/d0/d0/d0/d0/f3.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import React from 'react'
import Icon from '@icon-park/react/es/all';


function Navbar({ show }) {
return (
<div>

</div>
)
}

export default Navbar

Loading

2 comments on commit aa7326b

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on aa7326b Feb 14, 2025

Choose a reason for hiding this comment

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

πŸ“ Benchmark detail: Open

task failure

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on aa7326b Feb 14, 2025

Choose a reason for hiding this comment

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

πŸ“ Ecosystem CI detail: Open

suite result
modernjs βœ… success
rspress βœ… success
rslib βœ… success
rsbuild ❌ failure
rsdoctor ❌ failure
examples βœ… success
devserver βœ… success
nuxt βœ… success

Please sign in to comment.