Skip to content

Commit

Permalink
Only post comment on performance diff
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueDoctor committed Aug 14, 2024
1 parent 7683ca9 commit 8e46177
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions .github/workflows/profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,45 @@ jobs:
- name: Run PR benchmarks
id: benchmark
run: |
BENCH_OUTPUT=$(cargo bench --bench compile_demo_art --features=iai -- --baseline=master)
ESCAPED_OUTPUT=$(echo "$BENCH_OUTPUT" | jq -sR .)
echo "BENCHMARK_OUTPUT=$ESCAPED_OUTPUT" >> $GITHUB_OUTPUT
BENCH_OUTPUT=$(cargo bench --bench compile_demo_art --features=iai -- --baseline=master --output-format=json)
echo "BENCHMARK_OUTPUT<<EOF" >> $GITHUB_OUTPUT
echo "$BENCH_OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Comment PR
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const output = `#### Performance Benchmark Results
\`\`\`
${{ steps.benchmark.outputs.BENCHMARK_OUTPUT }}
\`\`\`
`;
const benchmarkOutput = JSON.parse('${{ steps.benchmark.outputs.BENCHMARK_OUTPUT }}');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
let significantChanges = false;
let commentBody = "#### Performance Benchmark Results\n\n";
for (const benchmark of benchmarkOutput) {
if (benchmark.callgrind_summary && benchmark.callgrind_summary.summaries) {
for (const summary of benchmark.callgrind_summary.summaries) {
for (const [eventKind, costsDiff] of Object.entries(summary.events)) {
if (costsDiff.diff_pct !== null && Math.abs(costsDiff.diff_pct) > 5) {
significantChanges = true;
const changeDirection = costsDiff.diff_pct > 0 ? "increase" : "decrease";
const color = costsDiff.diff_pct > 0 ? "red" : "green";
commentBody += `\`${benchmark.module_path}\` - ${eventKind}:\n`;
commentBody += `\\color{${color}}${changeDirection} of ${Math.abs(costsDiff.diff_pct).toFixed(2)}%\n`;
commentBody += `Old: ${costsDiff.old}, New: ${costsDiff.new}\n\n`;
}
}
}
}
}
if (significantChanges) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
} else {
console.log("No significant performance changes detected. Skipping comment.");
}

0 comments on commit 8e46177

Please sign in to comment.