Skip to content

Commit

Permalink
perf(bench): Run benchmark on a custom runner (#9877)
Browse files Browse the repository at this point in the history
**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.
  • Loading branch information
kdy1 authored Jan 14, 2025
1 parent 3df8b44 commit 2d6f9a5
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 162 deletions.
127 changes: 68 additions & 59 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,65 +24,27 @@ env:
SKIP_YARN_COREPACK_CHECK: 1

jobs:
# list-crates:
# if: >-
# ${{ !contains(github.event.head_commit.message, 'chore: ') }}
# name: List crates
# runs-on: ubuntu-latest
# outputs:
# crates: ${{ steps.list-crates.outputs.crates }}
# steps:
# - uses: actions/checkout@v4

# - name: Install Rust
# uses: actions-rs/toolchain@v1
# with:
# profile: minimal

# - name: List crates
# id: list-crates
# run: echo "crates=$(./scripts/cargo/get-crates.sh)" >> $GITHUB_OUTPUT

# bench-crate:
# name: Bench ${{ matrix.crate }}
# runs-on: ubuntu-latest
# needs:
# - list-crates
# strategy:
# fail-fast: false
# matrix:
# crate: ${{fromJson(needs.list-crates.outputs.crates)}}
# steps:
# - uses: actions/checkout@v4

# - name: Install Rust
# uses: actions-rs/toolchain@v1
# with:
# profile: minimal

# - uses: ./.github/actions/setup-node

# - name: Setup rust toolchain, cache and cargo-codspeed binary
# uses: moonrepo/setup-rust@v0
# with:
# channel: stable
# cache-target: release
# bins: cargo-codspeed

# - name: Build the benchmark target(s)
# run: cargo codspeed build -p ${{ matrix.crate }}

# - name: Run the benchmarks
# uses: CodSpeedHQ/action@v2
# with:
# run: cargo codspeed run -p ${{ matrix.crate }}
# token: ${{ secrets.CODSPEED_TOKEN }}

bench-all:
name: Bench everything
list-crates:
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') }}
name: List crates to benchmark
runs-on: ubuntu-22.04
outputs:
crates: ${{ steps.list-crates.outputs.crates }}
steps:
- uses: actions/checkout@v4

- name: List crates
id: list-crates
run: echo "crates=$(./scripts/bench/list-crates-with-bench.sh)" >> $GITHUB_OUTPUT

build-crate:
name: Build benchmark for ${{ matrix.crate }}
runs-on: ubuntu-22.04
needs: list-crates
strategy:
matrix:
crate: ${{fromJson(needs.list-crates.outputs.crates)}}
steps:
- uses: actions/checkout@v4

Expand All @@ -91,18 +53,65 @@ jobs:
with:
profile: minimal

- uses: ./.github/actions/setup-node
- uses: Swatinem/rust-cache@v2
# Some crates are too slow to build
if: matrix.crate == 'swc'
with:
shared-key: "bench-${{ matrix.crate }}"
key: "bench-${{ matrix.crate }}"
cache-all-crates: true

- name: Install cargo-codspeed
uses: taiki-e/install-action@v2
with:
tool: cargo-codspeed@2.7.2

- name: Build the benchmark target(s)
run: ./scripts/bench/build-all-crates.sh
run: ./scripts/bench/build-crate.sh ${{ matrix.crate }}

- name: Upload built artifacts
uses: actions/upload-artifact@v4
with:
name: bench-${{ matrix.crate }}
path: target/codspeed

bench-all:
name: Run benchmarks
needs: build-crate
runs-on:
- self-hosted
- linux
- x64
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') }}
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal

- name: Install cargo-codspeed
uses: taiki-e/install-action@v2
with:
tool: cargo-codspeed@2.7.2

- run: mkdir -p target/codspeed

- name: Download built artifacts
uses: actions/download-artifact@v4
with:
pattern: bench-*
path: target/codspeed
merge-multiple: true

- run: ls -alR target/codspeed

- run: chmod -R +x target/codspeed/*

- name: Run the benchmarks
uses: CodSpeedHQ/action@v2
uses: CodSpeedHQ/action@v3
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
4 changes: 0 additions & 4 deletions crates/swc_css_minifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,3 @@ swc_css_codegen = { version = "5.0.0", path = "../swc_css_codegen" }
swc_css_parser = { version = "5.0.0", path = "../swc_css_parser" }
swc_malloc = { version = "1.0.0", path = "../swc_malloc" }
testing = { version = "5.0.0", path = "../testing" }

[[bench]]
harness = false
name = "full"
63 changes: 0 additions & 63 deletions crates/swc_css_minifier/benches/full.rs

This file was deleted.

36 changes: 0 additions & 36 deletions scripts/bench/build-all-crates.sh

This file was deleted.

14 changes: 14 additions & 0 deletions scripts/bench/build-crate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -eu

crate=$1

# If crate has feature 'concurrent', build it with feature
if [[ $(./scripts/cargo/list-features.sh $crate) == *"concurrent"* ]]; then
echo "Building $crate with feature 'concurrent'"
cargo codspeed build -p $crate --features concurrent
else
echo "Building $crate"
cargo codspeed build -p $crate
fi
6 changes: 6 additions & 0 deletions scripts/bench/list-crates-with-bench.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -eu

WS_CRATES=$(./scripts/cargo/get-workspace-crates-json.sh)
echo "$WS_CRATES" | jq -r -c '[.[] | select(.targets[] | .kind | contains(["bench"])) | .name] | sort | unique' | jq -r -c '[.[] | select(. != "swc_plugin_runner")]'
5 changes: 5 additions & 0 deletions scripts/cargo/get-workspace-crates-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -eu

cargo metadata --format-version 1 --no-deps | jq -r -j '[.packages[] | select(.source == null and .name != "xtask")]'

0 comments on commit 2d6f9a5

Please sign in to comment.