forked from j178/prek
-
Notifications
You must be signed in to change notification settings - Fork 0
171 lines (143 loc) · 5.68 KB
/
performance.yml
File metadata and controls
171 lines (143 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: Performance
on:
workflow_call:
inputs:
save-rust-cache:
required: false
type: string
default: "true"
permissions: {}
env:
# Cargo env vars
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
CARGO_TERM_COLOR: always
RUSTUP_MAX_RETRIES: 10
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
bloat-check:
runs-on: ubuntu-latest
name: "bloat check"
timeout-minutes: 10
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
fetch-depth: 0
- uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
with:
save-if: ${{ inputs.save-rust-cache == 'true' }}
- uses: taiki-e/install-action@64c5c20c872907b6f7cd50994ac189e7274160f2 # v2.68.26
with:
tool: cargo-bloat
- name: Build head branch
id: bloat_head
run: |
# Build head branch
cargo bloat --release | tee bloat_head.txt >&1
- name: Checkout base
run: |
git checkout ${{ github.event.pull_request.base.sha }}
- name: Build base branch
id: bloat_base
run: |
# Build base branch
cargo bloat --release | tee bloat_base.txt >&1
- name: Compare bloat results
shell: python
run: |
import re
from pathlib import Path
def parse_size(text):
match = re.search(r'\.text section size.*?([\d.]+)\s*([KMGT]i?B)', text)
if not match:
raise ValueError("Could not find .text section size")
value, unit = float(match.group(1)), match.group(2)
multipliers = {'B': 1, 'KiB': 1024, 'MiB': 1024**2, 'GiB': 1024**3, 'TiB': 1024**4}
size = value * multipliers.get(unit, 1)
return size, f"{value} {unit}"
head_text = Path('bloat_head.txt').read_text()
base_text = Path('bloat_base.txt').read_text()
head_bytes, head_size = parse_size(head_text)
base_bytes, base_size = parse_size(base_text)
pct_change = ((head_bytes - base_bytes) / base_bytes) * 100
pct_display = f"{pct_change:+.2f}%"
comparison = f"""\
### 📦 Cargo Bloat Comparison
**Binary size change:** {pct_display} ({base_size} → {head_size})
<details>
<summary>Expand for cargo-bloat output</summary>
#### Head Branch Results
```
{head_text}
```
#### Base Branch Results
```
{base_text}
```
</details>
"""
Path("bloat-comparison.txt").write_text(comparison)
- name: Upload bloat results
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
# NOTE: https://github.com/j178/prek-ci-bot uses this artifact name to post comments on PRs.
# Make sure to update the bot if you rename the artifact.
name: bloat-check-results
path: bloat-comparison.txt
hyperfine-benchmark:
runs-on: ubuntu-latest
name: "hyperfine benchmark"
timeout-minutes: 10
env:
HYPERFINE_BENCHMARK_WORKSPACE: /tmp/prek-bench
HYPERFINE_BIN_DIR: ${{ github.workspace }}/.hyperfine-bin
HYPERFINE_RESULTS_FILE: ${{ github.workspace }}/hyperfine-benchmark.md
HYPERFINE_HEAD_BINARY: prek-head
HYPERFINE_BASE_BINARY: prek-base
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: Add hyperfine bin dir to PATH
run: |
mkdir -p "$HYPERFINE_BIN_DIR"
echo "$HYPERFINE_BIN_DIR" >> "$GITHUB_PATH"
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
with:
save-if: ${{ inputs.save-rust-cache == 'true' }}
- id: base-binary-cache
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: ${{ env.HYPERFINE_BIN_DIR }}/${{ env.HYPERFINE_BASE_BINARY }}
key: prek-hyperfine-base-${{ github.event.pull_request.base.sha }}-${{ hashFiles('Cargo.lock') }}-${{ runner.os }}-${{ runner.arch }}
- name: Build base version
if: ${{ steps.base-binary-cache.outputs.cache-hit != 'true' }}
env:
BASE_VERSION: ${{ github.event.pull_request.base.sha }}
run: |
git checkout ${{ github.event.pull_request.base.sha }}
cargo build --profile profiling && mv target/profiling/prek "$HYPERFINE_BIN_DIR/$HYPERFINE_BASE_BINARY"
git checkout ${{ github.sha }}
- name: Build head version
run: |
cargo build --profile profiling && mv target/profiling/prek "$HYPERFINE_BIN_DIR/$HYPERFINE_HEAD_BINARY"
- name: Install hyperfine
uses: taiki-e/install-action@64c5c20c872907b6f7cd50994ac189e7274160f2 # v2.68.26
with:
tool: hyperfine
- name: Setup test environment for builtin hooks
run: scripts/hyperfine-setup-test-env.sh
- name: Run benchmarks
run: scripts/hyperfine-run-benchmarks.sh
- name: Upload benchmark results
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
# NOTE: https://github.com/j178/prek-ci-bot uses this artifact name to post comments on PRs.
# Make sure to update the bot if you rename the artifact.
name: hyperfine-benchmark-results
path: ${{ env.HYPERFINE_RESULTS_FILE }}