From 6c2bb13f9d9ec522a938d8aba535a8a93758e43d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 10 Jan 2025 16:00:28 +0900 Subject: [PATCH] perf: Enable `concurrent` in codspeed bench (#9862) **Description:** This PR enables cargo feature `concurrent` for codspeed benchmark done by CI machine for crates that have a such feature. --- .github/workflows/bench.yml | 2 +- scripts/bench/build-all-crates.sh | 36 +++++++++++++++++++++++++++++++ scripts/cargo/list-features.sh | 9 ++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 scripts/bench/build-all-crates.sh create mode 100755 scripts/cargo/list-features.sh diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index 1abd5151c2f8..aef159a795fa 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -99,7 +99,7 @@ jobs: tool: cargo-codspeed@2.7.2 - name: Build the benchmark target(s) - run: cargo codspeed build --workspace --exclude swc_plugin_runner + run: ./scripts/bench/build-all-crates.sh - name: Run the benchmarks uses: CodSpeedHQ/action@v2 diff --git a/scripts/bench/build-all-crates.sh b/scripts/bench/build-all-crates.sh new file mode 100755 index 000000000000..147ef5e29088 --- /dev/null +++ b/scripts/bench/build-all-crates.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -eu + +echo "Building all crates for codspeed" + +WS_CRATES=$(./scripts/cargo/list-crates.sh) + +# Get crate names +CRATE_NAMES=$(echo "$WS_CRATES" | jq -r '.name') + +for crate in $CRATE_NAMES; do + # If crate is swc_plugin_runner, skip it + if [[ $crate == "swc_plugin_runner" ]]; then + continue + fi + + crate_info=$(echo "$WS_CRATES" | jq -r 'select(.name == "'$crate'")') + bench_targets=$(echo $crate_info | jq -r '.targets[] | select(.kind | contains(["bench"]))') + + + # If crate has no benchmark target, skip it + if [[ -z $bench_targets ]]; then + echo "Skipping $crate because it has no benchmark target" + continue + fi + + # 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 +done diff --git a/scripts/cargo/list-features.sh b/scripts/cargo/list-features.sh new file mode 100755 index 000000000000..f9cf8a2a3461 --- /dev/null +++ b/scripts/cargo/list-features.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -eu + + + +# Prints json for workspace crates + +cargo metadata --format-version 1 | jq -r '.packages[] | select(.source == null and .name == "'$1'") | .features' \ No newline at end of file