Skip to content

Commit befbbc9

Browse files
ci: use benchtools to benchmark the committer
1 parent 1dd17d0 commit befbbc9

File tree

1 file changed

+11
-71
lines changed

1 file changed

+11
-71
lines changed

.github/workflows/committer_ci.yml

Lines changed: 11 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
runs-on: namespace-profile-medium-ubuntu-24-04-amd64
6767
if: ${{ github.event_name == 'pull_request' }}
6868
steps:
69-
# Checkout the base branch to get the old code.
69+
# Checkout the base branch to benchmark the old code.
7070
- uses: actions/checkout@v4
7171
with:
7272
ref: ${{ github.base_ref }}
@@ -88,87 +88,27 @@ jobs:
8888
with:
8989
github_token: ${{ secrets.GITHUB_TOKEN }}
9090

91-
# Download the old benchmark inputs.
91+
# Auth with GCS for bench_tools to download inputs.
9292
- id: auth
9393
uses: "google-github-actions/auth@v2"
9494
with:
9595
credentials_json: ${{ secrets.COMMITER_PRODUCTS_EXT_WRITER_JSON }}
9696
- uses: "google-github-actions/setup-gcloud@v2"
97-
- run: echo "OLD_BENCH_INPUT_FILES_PREFIX=$(cat ./crates/starknet_committer_and_os_cli/src/committer_cli/tests/flow_test_files_prefix)" >> $GITHUB_ENV
98-
- run: gcloud storage cp -r gs://committer-testing-artifacts/$OLD_BENCH_INPUT_FILES_PREFIX/* ./crates/starknet_committer_and_os_cli/test_inputs
9997

100-
# List the existing benchmarks.
101-
- run: |
102-
cargo bench -p starknet_committer_and_os_cli -- --list | grep ': benchmark$' | sed -e "s/: benchmark$//" > benchmarks_list.txt
98+
# Benchmark the base branch code.
99+
- run: cargo run -p bench_tools -- run --package starknet_committer_and_os_cli --out /tmp/base_results
103100

104-
# Benchmark the old code.
105-
- run: cargo bench -p starknet_committer_and_os_cli
101+
# Save the input files from the base branch to use in the second benchmark.
102+
- run: cp -r crates/starknet_committer_and_os_cli/test_inputs /tmp/test_inputs
106103

107-
# Backup the downloaded files to avoid re-downloading them if they didn't change (overwritten by checkout).
108-
- run: mv ./crates/starknet_committer_and_os_cli/test_inputs/tree_flow_inputs.json ./crates/starknet_committer_and_os_cli/test_inputs/tree_flow_inputs.json_bu
109-
- run: mv ./crates/starknet_committer_and_os_cli/test_inputs/committer_flow_inputs.json ./crates/starknet_committer_and_os_cli/test_inputs/committer_flow_inputs.json_bu
110-
111-
# Checkout the new code.
104+
# Checkout the current branch to benchmark the new code.
112105
- uses: actions/checkout@v4
113106
with:
114107
clean: false
115-
- run: echo "NEW_BENCH_INPUT_FILES_PREFIX=$(cat ./crates/starknet_committer_and_os_cli/src/committer_cli/tests/flow_test_files_prefix)" >> $GITHUB_ENV
116108

117-
# If the pip requirements on the old commit are different from the new commit, re-install them.
109+
# Re-install pip requirements in case they changed between branches.
118110
- run: pip install -r scripts/requirements.txt
119111

120-
# Input files didn't change.
121-
- if: env.OLD_BENCH_INPUT_FILES_PREFIX == env.NEW_BENCH_INPUT_FILES_PREFIX
122-
run: |
123-
mv ./crates/starknet_committer_and_os_cli/test_inputs/tree_flow_inputs.json_bu ./crates/starknet_committer_and_os_cli/test_inputs/tree_flow_inputs.json
124-
mv ./crates/starknet_committer_and_os_cli/test_inputs/committer_flow_inputs.json_bu ./crates/starknet_committer_and_os_cli/test_inputs/committer_flow_inputs.json
125-
126-
# Input files did change, download new inputs.
127-
- if: env.OLD_BENCH_INPUT_FILES_PREFIX != env.NEW_BENCH_INPUT_FILES_PREFIX
128-
run: |
129-
gcloud storage cp -r gs://committer-testing-artifacts/$NEW_BENCH_INPUT_FILES_PREFIX/* ./crates/starknet_committer_and_os_cli/test_inputs
130-
131-
# Benchmark the new code, splitting the benchmarks, and prepare the results for posting a comment.
132-
- run: bash ./crates/starknet_committer_and_os_cli/benches/bench_split_and_prepare_post.sh benchmarks_list.txt benchmark_comment_body.txt
133-
134-
- run: echo BENCHES_RESULT=$(cat benchmark_comment_body.txt) >> $GITHUB_ENV
135-
136-
# Comment with a link to the workflow (or update existing comment on rerun).
137-
- name: Find Comment
138-
if: github.event_name == 'pull_request'
139-
uses: starkware-libs/find-comment@v3
140-
id: find-benchmark-comment
141-
with:
142-
token: ${{ secrets.GITHUB_TOKEN }}
143-
issue-number: ${{ github.event.pull_request.number }}
144-
comment-author: "github-actions[bot]"
145-
body-includes: Benchmark movements
146-
147-
- name: Create comment
148-
# If the PR number is found and the comment is not found, create a new comment.
149-
if: github.event_name == 'pull_request'
150-
&& steps.find-benchmark-comment.outputs.comment-id == ''
151-
uses: starkware-libs/create-or-update-comment@v4
152-
with:
153-
token: ${{ secrets.GITHUB_TOKEN }}
154-
issue-number: ${{ github.event.pull_request.number }}
155-
body: ${{ env.BENCHES_RESULT }}
156-
157-
- name: Update comment
158-
# If the PR number is found and the comment exists, update it.
159-
if: github.event_name == 'pull_request'
160-
&& steps.find-benchmark-comment.outputs.comment-id != ''
161-
uses: starkware-libs/create-or-update-comment@v4
162-
with:
163-
token: ${{ secrets.GITHUB_TOKEN }}
164-
comment-id: ${{ steps.find-benchmark-comment.outputs.comment-id }}
165-
edit-mode: replace
166-
body: ${{ env.BENCHES_RESULT }}
167-
168-
# Fail the job if benchmarks exceeded the threshold (after posting the comment).
169-
- name: Check benchmark results
170-
run: |
171-
if grep -q "CI WILL FAIL" benchmark_comment_body.txt; then
172-
echo "Benchmarks exceeded the regression threshold. See the PR comment for details."
173-
exit 1
174-
fi
112+
# Benchmark the current branch and compare to the previous run.
113+
# Use the saved inputs.
114+
- run: cargo run -p bench_tools -- run-and-compare --package starknet_committer_and_os_cli --out /tmp/new_results --regression-limit 8.0 --input-dir /tmp/test_inputs

0 commit comments

Comments
 (0)