Skip to content

Commit 2d6f9a5

Browse files
authoredJan 14, 2025··
perf(bench): Run benchmark on a custom runner (#9877)
**Description:** I configured one custom runner using https://github.com/myoung34/docker-github-actions-runner that has 16 cores and 64GB RAM. It's much quieter than a public GitHub runner, so I'll rely on this for profiling.
1 parent 3df8b44 commit 2d6f9a5

File tree

7 files changed

+93
-162
lines changed

7 files changed

+93
-162
lines changed
 

‎.github/workflows/bench.yml

+68-59
Original file line numberDiff line numberDiff line change
@@ -24,65 +24,27 @@ env:
2424
SKIP_YARN_COREPACK_CHECK: 1
2525

2626
jobs:
27-
# list-crates:
28-
# if: >-
29-
# ${{ !contains(github.event.head_commit.message, 'chore: ') }}
30-
# name: List crates
31-
# runs-on: ubuntu-latest
32-
# outputs:
33-
# crates: ${{ steps.list-crates.outputs.crates }}
34-
# steps:
35-
# - uses: actions/checkout@v4
36-
37-
# - name: Install Rust
38-
# uses: actions-rs/toolchain@v1
39-
# with:
40-
# profile: minimal
41-
42-
# - name: List crates
43-
# id: list-crates
44-
# run: echo "crates=$(./scripts/cargo/get-crates.sh)" >> $GITHUB_OUTPUT
45-
46-
# bench-crate:
47-
# name: Bench ${{ matrix.crate }}
48-
# runs-on: ubuntu-latest
49-
# needs:
50-
# - list-crates
51-
# strategy:
52-
# fail-fast: false
53-
# matrix:
54-
# crate: ${{fromJson(needs.list-crates.outputs.crates)}}
55-
# steps:
56-
# - uses: actions/checkout@v4
57-
58-
# - name: Install Rust
59-
# uses: actions-rs/toolchain@v1
60-
# with:
61-
# profile: minimal
62-
63-
# - uses: ./.github/actions/setup-node
64-
65-
# - name: Setup rust toolchain, cache and cargo-codspeed binary
66-
# uses: moonrepo/setup-rust@v0
67-
# with:
68-
# channel: stable
69-
# cache-target: release
70-
# bins: cargo-codspeed
71-
72-
# - name: Build the benchmark target(s)
73-
# run: cargo codspeed build -p ${{ matrix.crate }}
74-
75-
# - name: Run the benchmarks
76-
# uses: CodSpeedHQ/action@v2
77-
# with:
78-
# run: cargo codspeed run -p ${{ matrix.crate }}
79-
# token: ${{ secrets.CODSPEED_TOKEN }}
80-
81-
bench-all:
82-
name: Bench everything
27+
list-crates:
8328
if: >-
8429
${{ !contains(github.event.head_commit.message, 'chore: ') }}
30+
name: List crates to benchmark
31+
runs-on: ubuntu-22.04
32+
outputs:
33+
crates: ${{ steps.list-crates.outputs.crates }}
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: List crates
38+
id: list-crates
39+
run: echo "crates=$(./scripts/bench/list-crates-with-bench.sh)" >> $GITHUB_OUTPUT
40+
41+
build-crate:
42+
name: Build benchmark for ${{ matrix.crate }}
8543
runs-on: ubuntu-22.04
44+
needs: list-crates
45+
strategy:
46+
matrix:
47+
crate: ${{fromJson(needs.list-crates.outputs.crates)}}
8648
steps:
8749
- uses: actions/checkout@v4
8850

@@ -91,18 +53,65 @@ jobs:
9153
with:
9254
profile: minimal
9355

94-
- uses: ./.github/actions/setup-node
56+
- uses: Swatinem/rust-cache@v2
57+
# Some crates are too slow to build
58+
if: matrix.crate == 'swc'
59+
with:
60+
shared-key: "bench-${{ matrix.crate }}"
61+
key: "bench-${{ matrix.crate }}"
62+
cache-all-crates: true
9563

9664
- name: Install cargo-codspeed
9765
uses: taiki-e/install-action@v2
9866
with:
9967
tool: cargo-codspeed@2.7.2
10068

10169
- name: Build the benchmark target(s)
102-
run: ./scripts/bench/build-all-crates.sh
70+
run: ./scripts/bench/build-crate.sh ${{ matrix.crate }}
71+
72+
- name: Upload built artifacts
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: bench-${{ matrix.crate }}
76+
path: target/codspeed
77+
78+
bench-all:
79+
name: Run benchmarks
80+
needs: build-crate
81+
runs-on:
82+
- self-hosted
83+
- linux
84+
- x64
85+
if: >-
86+
${{ !contains(github.event.head_commit.message, 'chore: ') }}
87+
steps:
88+
- uses: actions/checkout@v4
89+
90+
- name: Install Rust
91+
uses: actions-rs/toolchain@v1
92+
with:
93+
profile: minimal
94+
95+
- name: Install cargo-codspeed
96+
uses: taiki-e/install-action@v2
97+
with:
98+
tool: cargo-codspeed@2.7.2
99+
100+
- run: mkdir -p target/codspeed
101+
102+
- name: Download built artifacts
103+
uses: actions/download-artifact@v4
104+
with:
105+
pattern: bench-*
106+
path: target/codspeed
107+
merge-multiple: true
108+
109+
- run: ls -alR target/codspeed
110+
111+
- run: chmod -R +x target/codspeed/*
103112

104113
- name: Run the benchmarks
105-
uses: CodSpeedHQ/action@v2
114+
uses: CodSpeedHQ/action@v3
106115
with:
107116
run: cargo codspeed run
108117
token: ${{ secrets.CODSPEED_TOKEN }}

‎crates/swc_css_minifier/Cargo.toml

-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,3 @@ swc_css_codegen = { version = "5.0.0", path = "../swc_css_codegen" }
2929
swc_css_parser = { version = "5.0.0", path = "../swc_css_parser" }
3030
swc_malloc = { version = "1.0.0", path = "../swc_malloc" }
3131
testing = { version = "5.0.0", path = "../testing" }
32-
33-
[[bench]]
34-
harness = false
35-
name = "full"

‎crates/swc_css_minifier/benches/full.rs

-63
This file was deleted.

‎scripts/bench/build-all-crates.sh

-36
This file was deleted.

‎scripts/bench/build-crate.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
crate=$1
6+
7+
# If crate has feature 'concurrent', build it with feature
8+
if [[ $(./scripts/cargo/list-features.sh $crate) == *"concurrent"* ]]; then
9+
echo "Building $crate with feature 'concurrent'"
10+
cargo codspeed build -p $crate --features concurrent
11+
else
12+
echo "Building $crate"
13+
cargo codspeed build -p $crate
14+
fi
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
WS_CRATES=$(./scripts/cargo/get-workspace-crates-json.sh)
6+
echo "$WS_CRATES" | jq -r -c '[.[] | select(.targets[] | .kind | contains(["bench"])) | .name] | sort | unique' | jq -r -c '[.[] | select(. != "swc_plugin_runner")]'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
cargo metadata --format-version 1 --no-deps | jq -r -j '[.packages[] | select(.source == null and .name != "xtask")]'

0 commit comments

Comments
 (0)
Please sign in to comment.