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

Use Codspeed for continous benchmarking #6896

Merged
merged 1 commit into from
Aug 26, 2023
Merged
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
136 changes: 0 additions & 136 deletions .github/workflows/benchmark.yaml

This file was deleted.

25 changes: 25 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,28 @@ jobs:
run: cat target/progress_projects_stats.txt > $GITHUB_STEP_SUMMARY
- name: "Remove checkouts from cache"
run: rm -r target/progress_projects

benchmarks:
runs-on: ubuntu-latest
steps:
- name: "Checkout Branch"
uses: actions/checkout@v3

- name: "Install Rust toolchain"
run: rustup show

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

- uses: Swatinem/rust-cache@v2

- name: "Build benchmarks"
run: cargo codspeed build --features codspeed -p ruff_benchmark

- name: "Run benchmarks"
uses: CodSpeedHQ/action@v1
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
29 changes: 5 additions & 24 deletions .github/workflows/pr-comment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: PR Check Comment

on:
workflow_run:
workflows: [CI, Benchmark]
workflows: [CI]
types: [completed]
workflow_dispatch:
inputs:
Expand Down Expand Up @@ -43,35 +43,16 @@ jobs:
path: pr/ecosystem
if_no_artifact_found: ignore

- uses: dawidd6/action-download-artifact@v2
name: "Download Benchmark Result"
id: download-benchmark-result
if: steps.pr-number.outputs.pr-number
with:
name: summary
workflow: benchmark.yaml
pr: ${{ steps.pr-number.outputs.pr-number }}
path: pr/benchmark
if_no_artifact_found: ignore

- name: Generate Comment
id: generate-comment
if: steps.download-ecosystem-result.outputs.found_artifact == 'true' || steps.download-benchmark-result.outputs.found_artifact == 'true'
if: steps.download-ecosystem-result.outputs.found_artifact == 'true'
run: |
echo 'comment<<EOF' >> $GITHUB_OUTPUT
echo '## PR Check Results' >> $GITHUB_OUTPUT

if [[ -f pr/ecosystem/ecosystem-result ]]
then
echo "### Ecosystem" >> $GITHUB_OUTPUT
cat pr/ecosystem/ecosystem-result >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
fi

if [[ -f pr/benchmark/summary.md ]]
then
cat pr/benchmark/summary.md >> $GITHUB_OUTPUT
fi
echo "### Ecosystem" >> $GITHUB_OUTPUT
cat pr/ecosystem/ecosystem-result >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT

echo 'EOF' >> $GITHUB_OUTPUT

Expand Down
27 changes: 25 additions & 2 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion crates/ruff_benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ serde.workspace = true
serde_json.workspace = true
url = "2.3.1"
ureq = "2.6.2"
criterion = { version = "0.5.1"}
codspeed-criterion-compat = { version="2.1.0", optional = true}

[dev-dependencies]
ruff.path = "../ruff"
ruff_python_ast.path = "../ruff_python_ast"
ruff_python_formatter = { path = "../ruff_python_formatter" }
ruff_python_index = { path = "../ruff_python_index" }
ruff_python_parser = { path = "../ruff_python_parser" }
criterion = { version = "0.5.1"}

[features]
codspeed = ["codspeed-criterion-compat"]

[target.'cfg(target_os = "windows")'.dev-dependencies]
mimalloc = "0.1.34"
Expand Down
5 changes: 3 additions & 2 deletions crates/ruff_benchmark/benches/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::path::Path;
use std::time::Duration;

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};

use ruff_benchmark::criterion::{
criterion_group, criterion_main, BenchmarkId, Criterion, Throughput,
};
use ruff_benchmark::{TestCase, TestCaseSpeed, TestFile, TestFileDownloadError};
use ruff_python_formatter::{format_node, PyFormatOptions};
use ruff_python_index::CommentRangesBuilder;
Expand Down
10 changes: 4 additions & 6 deletions crates/ruff_benchmark/benches/linter.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::time::Duration;

use criterion::measurement::WallTime;
use criterion::{
criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion, Throughput,
};

use ruff::linter::lint_only;
use ruff::settings::{flags, Settings};
use ruff::source_kind::SourceKind;
use ruff::RuleSelector;
use ruff_benchmark::criterion::{
criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion, Throughput,
};
use ruff_benchmark::{TestCase, TestCaseSpeed, TestFile, TestFileDownloadError};
use ruff_python_ast::PySourceType;

Expand Down Expand Up @@ -43,7 +41,7 @@ fn create_test_cases() -> Result<Vec<TestCase>, TestFileDownloadError> {
])
}

fn benchmark_linter(mut group: BenchmarkGroup<WallTime>, settings: &Settings) {
fn benchmark_linter(mut group: BenchmarkGroup, settings: &Settings) {
let test_cases = create_test_cases().unwrap();

for case in test_cases {
Expand Down
5 changes: 3 additions & 2 deletions crates/ruff_benchmark/benches/parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::time::Duration;

use criterion::measurement::WallTime;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use ruff_benchmark::criterion::{
criterion_group, criterion_main, measurement::WallTime, BenchmarkId, Criterion, Throughput,
};
use ruff_benchmark::{TestCase, TestCaseSpeed, TestFile, TestFileDownloadError};
use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor};
use ruff_python_ast::Stmt;
Expand Down
11 changes: 11 additions & 0 deletions crates/ruff_benchmark/src/criterion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! This module re-exports the criterion API but picks the right backend depending on whether
//! the benchmarks are built to run locally or with codspeed

#[cfg(not(codspeed))]
pub use criterion::*;

#[cfg(not(codspeed))]
pub type BenchmarkGroup<'a> = criterion::BenchmarkGroup<'a, measurement::WallTime>;

#[cfg(codspeed)]
pub use codspeed_criterion_compat::*;
2 changes: 2 additions & 0 deletions crates/ruff_benchmark/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod criterion;

use std::fmt::{Display, Formatter};
use std::path::PathBuf;
use std::process::Command;
Expand Down
Loading