Unverified Commit cc3c42f8 authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

chore(ci): Configure small benchmark for builds (#79796)

### What?

We can use codspeed for profiling the build performance, considering that these apps are very small.

### Why?

We need an  e2e benchmark.
parent 6c7a69ad
...@@ -42,6 +42,10 @@ jobs: ...@@ -42,6 +42,10 @@ jobs:
check-latest: true check-latest: true
- run: corepack enable - run: corepack enable
# We need to install the dependencies for the benchmark apps
- run: pnpm install
working-directory: turbopack/benchmark-apps
- name: Build benchmarks for tests - name: Build benchmarks for tests
timeout-minutes: 120 timeout-minutes: 120
run: | run: |
......
...@@ -25,10 +25,13 @@ env: ...@@ -25,10 +25,13 @@ env:
CARGO_INCREMENTAL: 0 CARGO_INCREMENTAL: 0
# For faster CI # For faster CI
RUST_LOG: 'off' RUST_LOG: 'off'
TURBO_TEAM: 'vercel'
TURBO_CACHE: 'remote:rw'
TURBO_TOKEN: ${{ secrets.HOSTED_TURBO_TOKEN }}
jobs: jobs:
benchmark-small: benchmark-tiny:
name: Benchmark Rust Crates (small) name: Benchmark Rust Crates (tiny)
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
...@@ -50,6 +53,43 @@ jobs: ...@@ -50,6 +53,43 @@ jobs:
run: cargo codspeed run run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }} token: ${{ secrets.CODSPEED_TOKEN }}
benchmark-small-apps:
name: Benchmark Rust Crates (small apps)
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: ./.github/actions/setup-rust
- name: Install cargo-codspeed
uses: taiki-e/install-action@v2
with:
tool: cargo-codspeed@2.10.1
- name: Cache on ${{ github.ref_name }}
uses: ijjk/rust-cache@turbo-cache-v1.0.8
with:
save-if: 'true'
cache-provider: 'turbo'
shared-key: build-turbopack-benchmark-small-apps-${{ hashFiles('.cargo/config.toml') }}
- name: Install pnpm dependencies
working-directory: turbopack/benchmark-apps
run: |
npm i -g corepack@0.31
corepack enable
pnpm install --loglevel error
- name: Build app build benchmarks
run: cargo codspeed build -p turbopack-cli small_apps
- name: Run the benchmarks
uses: CodSpeedHQ/action@v3
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
benchmark-large: benchmark-large:
name: Benchmark Rust Crates (large) name: Benchmark Rust Crates (large)
# If the task is triggered manually, we want to run the large benchmarks # If the task is triggered manually, we want to run the large benchmarks
......
# Benchmark Apps
This directory contains apps that are used to benchmark the performance of Turbopack.
import * as React from 'react'
import * as DateFns from 'date-fns'
console.log(DateFns)
export default function Home() {
return <div>Benchmark</div>
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src-mui/index.tsx"></script>
</body>
</html>
import * as React from 'react'
import * as ReactDOM from 'react-dom/client'
import App from './App'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
import * as React from 'react'
import { format } from 'date-fns'
export default function Home() {
return <div>{format(new Date(), "'Today is a' eeee")}</div>
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src-mui/index.tsx"></script>
</body>
</html>
import * as React from 'react'
import * as ReactDOM from 'react-dom/client'
import App from './App'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
/* eslint-disable react/jsx-pascal-case */
import * as React from 'react'
import * as FramerMotion from 'framer-motion'
console.log(FramerMotion)
export default function Home() {
return (
<div>
<FramerMotion.motion.div animate={{ x: 0 }} />
</div>
)
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src-mui/index.tsx"></script>
</body>
</html>
import * as React from 'react'
import * as ReactDOM from 'react-dom/client'
import App from './App'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
import * as React from 'react'
import { motion } from 'framer-motion'
export default function Home() {
return (
<div>
<motion.div animate={{ x: 0 }} />
</div>
)
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src-mui/index.tsx"></script>
</body>
</html>
import * as React from 'react'
import * as ReactDOM from 'react-dom/client'
import App from './App'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
import * as React from 'react'
import { Container, Typography, Box, Link } from '@mui/joy'
import ProTip from './ProTip'
function Copyright() {
return (
<Typography
textAlign="center"
sx={{
color: 'text.secondary',
}}
>
{'Copyright © '}
<Link href="https://mui.com/">Your Website</Link>{' '}
{new Date().getFullYear()}.
</Typography>
)
}
export default function App() {
return (
<Container maxWidth="sm">
<Box sx={{ my: 4 }}>
<Typography level="h4" component="h1" sx={{ mb: 2 }}>
Material UI Vite.js example in TypeScript
</Typography>
<ProTip />
<Copyright />
</Box>
</Container>
)
}
import * as React from 'react'
import { Link, Typography, SvgIcon, type SvgIconProps } from '@mui/joy'
function LightBulbIcon(props: SvgIconProps) {
return (
<SvgIcon {...props}>
<path d="M9 21c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-1H9v1zm3-19C8.14 2 5 5.14 5 9c0 2.38 1.19 4.47 3 5.74V17c0 .55.45 1 1 1h6c.55 0 1-.45 1-1v-2.26c1.81-1.27 3-3.36 3-5.74 0-3.86-3.14-7-7-7zm2.85 11.1l-.85.6V16h-4v-2.3l-.85-.6C7.8 12.16 7 10.63 7 9c0-2.76 2.24-5 5-5s5 2.24 5 5c0 1.63-.8 3.16-2.15 4.1z" />
</SvgIcon>
)
}
export default function ProTip() {
return (
<Typography sx={{ mt: 6, mb: 3, color: 'text.secondary' }}>
<LightBulbIcon sx={{ mr: 1, verticalAlign: 'middle' }} />
{'Pro tip: See more '}
<Link href="https://mui.com/material-ui/getting-started/templates/">
templates
</Link>
{' in the Material UI documentation.'}
</Typography>
)
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src-joy/index.tsx"></script>
</body>
</html>
import * as React from 'react'
import * as ReactDOM from 'react-dom/client'
import { CssBaseline } from '@mui/joy'
import App from './App'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<CssBaseline />
<App />
</React.StrictMode>
)
import * as React from 'react'
import * as Icons from 'lucide-react'
export default function Home() {
const dynamicName = 'Camera'
const Icon = Icons[dynamicName]
return (
<div>
<Icon />
</div>
)
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src-mui/index.tsx"></script>
</body>
</html>
import * as React from 'react'
import * as ReactDOM from 'react-dom/client'
import App from './App'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
import * as React from 'react'
import { Camera } from 'lucide-react'
export default function Home() {
return (
<div>
<Camera />
</div>
)
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src-mui/index.tsx"></script>
</body>
</html>
import * as React from 'react'
import * as ReactDOM from 'react-dom/client'
import App from './App'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
import * as React from 'react'
import Container from '@mui/material/Container'
import Typography from '@mui/material/Typography'
import Box from '@mui/material/Box'
import Link from '@mui/material/Link'
import ProTip from './components/ProTip'
import Copyright from './components/Copyright'
export default function Home() {
return (
<Container maxWidth="lg">
<Box
sx={{
my: 4,
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI - Next.js App Router example in TypeScript
</Typography>
<Link href="/about" color="secondary">
Go to the about page
</Link>
<ProTip />
<Copyright />
</Box>
</Container>
)
}
import * as React from 'react'
import Link from '@mui/material/Link'
import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon'
import Typography from '@mui/material/Typography'
function LightBulbIcon(props: SvgIconProps) {
return (
<SvgIcon {...props}>
<path d="M9 21c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-1H9v1zm3-19C8.14 2 5 5.14 5 9c0 2.38 1.19 4.47 3 5.74V17c0 .55.45 1 1 1h6c.55 0 1-.45 1-1v-2.26c1.81-1.27 3-3.36 3-5.74 0-3.86-3.14-7-7-7zm2.85 11.1l-.85.6V16h-4v-2.3l-.85-.6C7.8 12.16 7 10.63 7 9c0-2.76 2.24-5 5-5s5 2.24 5 5c0 1.63-.8 3.16-2.15 4.1z" />
</SvgIcon>
)
}
export default function ProTip() {
return (
<Typography sx={{ mt: 6, mb: 3, color: 'text.secondary' }}>
<LightBulbIcon sx={{ mr: 1, verticalAlign: 'middle' }} />
{'Pro tip: See more '}
<Link href="https://mui.com/material-ui/getting-started/templates/">
templates
</Link>
{' in the Material UI documentation.'}
</Typography>
)
}
import * as React from 'react'
import Typography from '@mui/material/Typography'
import MuiLink from '@mui/material/Link'
export default function Copyright() {
return (
<Typography
variant="body2"
align="center"
sx={{
color: 'text.secondary',
}}
>
{'Copyright © '}
<MuiLink color="inherit" href="https://mui.com/">
Your Website
</MuiLink>{' '}
{new Date().getFullYear()}.
</Typography>
)
}
'use client'
import * as React from 'react'
import Box from '@mui/material/Box'
import FormControl from '@mui/material/FormControl'
import InputLabel from '@mui/material/InputLabel'
import MenuItem from '@mui/material/MenuItem'
import Select from '@mui/material/Select'
import { useColorScheme } from '@mui/material/styles'
export default function ModeSwitch() {
const { mode, setMode } = useColorScheme()
if (!mode) {
return null
}
return (
<Box
sx={{
display: 'flex',
justifyContent: 'flex-end',
mt: 1,
p: 1,
}}
>
<FormControl>
<InputLabel id="mode-select-label">Theme</InputLabel>
<Select
labelId="mode-select-label"
id="mode-select"
value={mode}
onChange={(event) => setMode(event.target.value as typeof mode)}
label="Theme"
>
<MenuItem value="system">System</MenuItem>
<MenuItem value="light">Light</MenuItem>
<MenuItem value="dark">Dark</MenuItem>
</Select>
</FormControl>
</Box>
)
}
import * as React from 'react'
import Link from '@mui/material/Link'
import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon'
import Typography from '@mui/material/Typography'
function LightBulbIcon(props: SvgIconProps) {
return (
<SvgIcon {...props}>
<path d="M9 21c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-1H9v1zm3-19C8.14 2 5 5.14 5 9c0 2.38 1.19 4.47 3 5.74V17c0 .55.45 1 1 1h6c.55 0 1-.45 1-1v-2.26c1.81-1.27 3-3.36 3-5.74 0-3.86-3.14-7-7-7zm2.85 11.1l-.85.6V16h-4v-2.3l-.85-.6C7.8 12.16 7 10.63 7 9c0-2.76 2.24-5 5-5s5 2.24 5 5c0 1.63-.8 3.16-2.15 4.1z" />
</SvgIcon>
)
}
export default function ProTip() {
return (
<Typography sx={{ mt: 6, mb: 3, color: 'text.secondary' }}>
<LightBulbIcon sx={{ mr: 1, verticalAlign: 'middle' }} />
{'Pro tip: See more '}
<Link href="https://mui.com/material-ui/getting-started/templates/">
templates
</Link>
{' in the Material UI documentation.'}
</Typography>
)
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src-mui/index.tsx"></script>
</body>
</html>
import * as React from 'react'
import * as ReactDOM from 'react-dom/client'
import ThemeProvider from '@mui/material/styles/ThemeProvider'
import CssBaseline from '@mui/material/CssBaseline'
import InitColorSchemeScript from '@mui/material/InitColorSchemeScript'
import ModeSwitch from './components/ModeSwitch'
import theme from './theme'
import App from './App'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<ThemeProvider theme={theme}>
<InitColorSchemeScript attribute="class" />
<ThemeProvider theme={theme}>
<CssBaseline />
<ModeSwitch />
<App />
</ThemeProvider>
</ThemeProvider>
</React.StrictMode>
)
import { createTheme } from '@mui/material/styles'
import { red } from '@mui/material/colors'
// A custom theme for this app
const theme = createTheme({
cssVariables: true,
palette: {
primary: {
main: '#556cd6',
},
secondary: {
main: '#19857b',
},
error: {
main: red.A400,
},
},
})
export default theme
{
"dependencies": {
"@emotion/cache": "11.14.0",
"@emotion/react": "11.14.0",
"@emotion/styled": "11.14.0",
"@iconify-icons/material-symbols": "1.2.58",
"@iconify/react": "5.1.0",
"@mui/icons-material": "6.2.1",
"@mui/joy": "5.0.0-beta.51",
"@mui/material": "6.2.1",
"@next/react-refresh-utils": "15.1.2",
"@types/react": "19.0.2",
"@types/react-dom": "19.0.2",
"date-fns": "^4.1.0",
"file-loader": "^6.2.0",
"framer-motion": "^12.0.0",
"lucide-react": "^0.471.1",
"markdown-table": "3.0.4",
"react": "19.0.0",
"react-dom": "19.0.0",
"react-refresh": "0.16.0",
"react-router-dom": "7.0.2",
"shiki": "^1.27.2",
"typescript": "5.7.2",
"vega-lite": "5.23.0"
},
"devDependencies": {
"buffer": "^5.5.0||^6.0.0",
"process": "0.11.10"
},
"packageManager": "pnpm@9.6.0"
}
This source diff could not be displayed because it is too large. You can view the blob instead.
import * as React from 'react'
import { codeToHtml } from 'shiki'
const code = 'const a = 1' // input code
export default async function Home() {
const html = await codeToHtml(code, {
lang: 'javascript',
theme: 'vitesse-dark',
})
return <pre>{html}</pre>
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src-mui/index.tsx"></script>
</body>
</html>
import * as React from 'react'
import * as ReactDOM from 'react-dom/client'
import App from './App'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
...@@ -155,7 +155,7 @@ pub trait AsyncBencherExtension<A: AsyncExecutor> { ...@@ -155,7 +155,7 @@ pub trait AsyncBencherExtension<A: AsyncExecutor> {
TF: Future<Output = ()>; TF: Future<Output = ()>;
} }
impl<A: AsyncExecutor> AsyncBencherExtension<A> for AsyncBencher<'_, '_, A, WallTime> { impl<A: AsyncExecutor> AsyncBencherExtension<A> for AsyncBencher<'_, '_, A> {
fn try_iter_custom<R, F>(&mut self, routine: R) fn try_iter_custom<R, F>(&mut self, routine: R)
where where
R: Fn(u64, WallTime) -> F, R: Fn(u64, WallTime) -> F,
......
...@@ -18,6 +18,10 @@ bench = false ...@@ -18,6 +18,10 @@ bench = false
name = "mod" name = "mod"
harness = false harness = false
[[bench]]
name = "small_apps"
harness = false
[features] [features]
default = ["custom_allocator"] default = ["custom_allocator"]
serializable = [] serializable = []
......
#![cfg_attr(not(codspeed), allow(unused))]
use std::{
path::{Path, PathBuf},
process::Command,
};
use criterion::{Criterion, criterion_group, criterion_main};
use turbopack_cli::{
arguments::{BuildArguments, CommonArguments},
register,
};
fn list_apps() -> (PathBuf, Vec<PathBuf>) {
// We need to rely on `CARGO_MANIFEST_DIR` because we are running it via `cargo codspeed`
let manifest_dir = env!("CARGO_MANIFEST_DIR");
let apps_dir = Path::new(&manifest_dir)
.join("../../benchmark-apps")
.canonicalize()
.expect("failed to canonicalize path");
let mut apps = Vec::new();
for entry in std::fs::read_dir(&apps_dir).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
if path.is_dir() {
// Exclude node_modules
if path.file_name().unwrap().to_string_lossy() == "node_modules" {
continue;
}
apps.push(path);
}
}
(apps_dir, apps)
}
fn bench_small_apps(c: &mut Criterion) {
use turbo_tasks_malloc::TurboMalloc;
register();
let (apps_dir, apps) = list_apps();
let mut g = c.benchmark_group("turbopack/build/apps");
for app in apps {
g.bench_function(app.to_string_lossy().to_string(), |b| {
let apps_dir = apps_dir.clone();
let app = app.clone();
b.iter(move || {
let mut rt = tokio::runtime::Builder::new_multi_thread();
rt.enable_all().on_thread_stop(|| {
TurboMalloc::thread_stop();
});
let rt = rt.build().unwrap();
let apps_dir = apps_dir.clone();
let app = app.clone();
let app_name = app.file_name().unwrap().to_string_lossy().to_string();
rt.block_on(async move {
//
turbopack_cli::build::build(&BuildArguments {
common: CommonArguments {
entries: Some(vec![format!("{app_name}/index.tsx")]),
dir: Some(app.clone()),
root: Some(apps_dir),
log_level: None,
show_all: false,
log_detail: false,
full_stats: false,
target: None,
},
no_sourcemap: false,
no_minify: false,
force_memory_cleanup: true,
})
.await
})
.unwrap();
});
});
}
}
criterion_group!(
name = benches;
config = Criterion::default().sample_size(10);
targets = bench_small_apps
);
criterion_main!(benches);
use turbo_tasks_build::generate_register; use turbo_tasks_build::generate_register;
fn main() { fn main() {
println!("cargo::rustc-check-cfg=cfg(codspeed)");
generate_register(); generate_register();
} }
...@@ -24,16 +24,15 @@ static ALLOC: TurboMalloc = TurboMalloc; ...@@ -24,16 +24,15 @@ static ALLOC: TurboMalloc = TurboMalloc;
fn main() { fn main() {
let args = Arguments::parse(); let args = Arguments::parse();
tokio::runtime::Builder::new_multi_thread() let mut rt = tokio::runtime::Builder::new_multi_thread();
.enable_all() rt.enable_all().on_thread_stop(|| {
.on_thread_stop(|| { TurboMalloc::thread_stop();
TurboMalloc::thread_stop(); });
})
.disable_lifo_slot() #[cfg(not(codspeed))]
.build() rt.disable_lifo_slot();
.unwrap()
.block_on(main_inner(args)) rt.build().unwrap().block_on(main_inner(args)).unwrap();
.unwrap();
} }
async fn main_inner(args: Arguments) -> Result<()> { async fn main_inner(args: Arguments) -> Result<()> {
......
...@@ -62,7 +62,9 @@ pub fn normalize_entries(entries: &Option<Vec<String>>) -> Vec<RcStr> { ...@@ -62,7 +62,9 @@ pub fn normalize_entries(entries: &Option<Vec<String>>) -> Vec<RcStr> {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn project_fs(project_dir: RcStr) -> Result<Vc<Box<dyn FileSystem>>> { pub async fn project_fs(project_dir: RcStr) -> Result<Vc<Box<dyn FileSystem>>> {
let disk_fs = DiskFileSystem::new("project".into(), project_dir, vec![]); let disk_fs = DiskFileSystem::new("project".into(), project_dir, vec![]);
disk_fs.await?.start_watching(None).await?; if cfg!(not(codspeed)) {
disk_fs.await?.start_watching(None).await?;
}
Ok(Vc::upcast(disk_fs)) Ok(Vc::upcast(disk_fs))
} }
......
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