Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): Configure codspeed #76884

Draft
wants to merge 7 commits into
base: canary
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Benchmark

on:
push:
branches:
- canary
paths:
- '**/crates/**'
pull_request:
types: ['labeled']

concurrency:
group: ${{ github.workflow }}-${{ github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
CI: 1
CARGO_INCREMENTAL: 0
# For faster CI
RUST_LOG: 'off'
# https://github.com/actions/setup-node/issues/899#issuecomment-1819151595
SKIP_YARN_COREPACK_CHECK: 1
Comment on lines +17 to +22
Copy link
Member

Choose a reason for hiding this comment

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

We should consider using build_reusable.yml to handle stuff like this, but that's not a blocker and can be a longer-term follow-up. https://github.com/search?q=repo%3Avercel%2Fnext.js%20build_reusable&type=code

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow! I didn't know that such thing is possible in GH Actions


jobs:
list-crates:
name: List crates to benchmark
runs-on:
- 'self-hosted'
- 'linux'
- 'x64'
- 'metal'
if: ${{ github.event.label.name == 'benchmark' }}
outputs:
crates: ${{ steps.list-crates.outputs.crates }}
steps:
- uses: actions/checkout@v4

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

benchmark-crate:
name: Benchmark ${{ matrix.crate }}
runs-on: ubuntu-22.04
needs: list-crates
strategy:
matrix:
crate: ${{fromJson(needs.list-crates.outputs.crates)}}
Copy link
Member

Choose a reason for hiding this comment

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

Can we do something to limit this parallelism? I'm concerned that we could end up with a lot of crates over time, and sharding has some cost and reliability tradeoffs.

For tests, we divide between a fixed number of workers. Tests have a complicated system that takes into account timings from previous executions that @ijjk wrote to reduce latency, but we can do something simple here for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. I'll think a bit more about this. (I'm not sure how should I split it)

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: [email protected]

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

- name: Run the benchmarks
uses: CodSpeedHQ/action@v3
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
24 changes: 12 additions & 12 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions scripts/cargo/bench/get-workspace-crates.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)]'
8 changes: 8 additions & 0 deletions scripts/cargo/bench/list-crates-with-bench.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -eu

SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

WS_CRATES="$("$SCRIPT_DIR"/get-workspace-crates.sh)"
echo "$WS_CRATES" | jq -r -c '[.[] | select(.targets[] | .kind | contains(["bench"])) | .name] | sort | unique' | jq -r -c '[.[] | select(. != "napi" and . != "wasm")]'
Copy link
Member

Choose a reason for hiding this comment

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

I don't know enough to say there's a problem here, but it seems suspicious that you're piping jq to jq.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, if you mean jq | jq, it's because while triaging it worked :trollface:

Loading