Skip to content

Commit 4fc2757

Browse files
committed
Add memory benchmark.
1 parent ccf81c7 commit 4fc2757

4 files changed

Lines changed: 9221 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,22 @@ jobs:
8989
- name: Ensure gh-pages branch exists
9090
run: |
9191
if ! git ls-remote --exit-code --heads origin gh-pages > /dev/null 2>&1; then
92-
# Create an orphan gh-pages branch without leaving the current checkout.
93-
# Build an empty tree and commit it, then push as the new branch.
9492
git config user.name "github-actions[bot]"
9593
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
9694
empty_tree="$(git hash-object -t tree /dev/null)"
9795
commit="$(git commit-tree "$empty_tree" -m 'Initial gh-pages branch')"
9896
git push origin "$commit:refs/heads/gh-pages"
9997
fi
10098
- name: Run benchmarks
101-
run: cargo bench --bench completion -- --output-format bencher | tee output.txt
99+
run: cargo bench --bench completion -- --output-format bencher | tee raw_output.txt
100+
- name: Convert to milliseconds
101+
run: python3 benches/format_bench_output.py < raw_output.txt > output.json
102102
- name: Store benchmark result
103103
uses: benchmark-action/github-action-benchmark@v1
104104
with:
105105
name: PHPantom Benchmarks
106-
tool: cargo
107-
output-file-path: output.txt
106+
tool: customSmallerIsBetter
107+
output-file-path: output.json
108108
gh-pages-branch: gh-pages
109109
benchmark-data-dir-path: dev/bench
110110
auto-push: true
@@ -131,14 +131,17 @@ jobs:
131131
fi
132132
- name: Run benchmarks
133133
if: steps.check-gh-pages.outputs.exists == 'true'
134-
run: cargo bench --bench completion -- --output-format bencher | tee output.txt
134+
run: cargo bench --bench completion -- --output-format bencher | tee raw_output.txt
135+
- name: Convert to milliseconds
136+
if: steps.check-gh-pages.outputs.exists == 'true'
137+
run: python3 benches/format_bench_output.py < raw_output.txt > output.json
135138
- name: Compare against baseline
136139
if: steps.check-gh-pages.outputs.exists == 'true'
137140
uses: benchmark-action/github-action-benchmark@v1
138141
with:
139142
name: PHPantom Benchmarks
140-
tool: cargo
141-
output-file-path: output.txt
143+
tool: customSmallerIsBetter
144+
output-file-path: output.json
142145
gh-pages-branch: gh-pages
143146
benchmark-data-dir-path: dev/bench
144147
auto-push: false
@@ -147,3 +150,93 @@ jobs:
147150
alert-threshold: "130%"
148151
fail-on-alert: true
149152
alert-comment-cc-users: "@AJenbo"
153+
154+
memory-benchmark:
155+
name: Memory Benchmark
156+
runs-on: ubuntu-latest
157+
needs: benchmark
158+
permissions:
159+
contents: write
160+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
161+
steps:
162+
- uses: actions/checkout@v4
163+
- uses: dtolnay/rust-toolchain@stable
164+
- uses: Swatinem/rust-cache@v2
165+
with:
166+
shared-key: build
167+
- uses: shivammathur/setup-php@v2
168+
with:
169+
php-version: "8.4"
170+
tools: composer
171+
- name: Install mold linker
172+
run: sudo apt-get install -y mold
173+
- name: Configure mold
174+
run: |
175+
mkdir -p .cargo
176+
echo '[target.x86_64-unknown-linux-gnu]' >> .cargo/config.toml
177+
echo 'rustflags = ["-C", "link-arg=-fuse-ld=mold"]' >> .cargo/config.toml
178+
- name: Build release binary
179+
run: cargo build --release
180+
- name: Measure memory usage
181+
run: python3 benches/memory_usage.py --binary target/release/phpantom_lsp | tee memory_output.json
182+
- name: Store memory benchmark result
183+
uses: benchmark-action/github-action-benchmark@v1
184+
with:
185+
name: PHPantom Memory Usage
186+
tool: customSmallerIsBetter
187+
output-file-path: memory_output.json
188+
gh-pages-branch: gh-pages
189+
benchmark-data-dir-path: dev/memory
190+
auto-push: true
191+
github-token: ${{ secrets.GITHUB_TOKEN }}
192+
193+
memory-benchmark-pr:
194+
name: Memory Benchmark (PR comparison)
195+
runs-on: ubuntu-latest
196+
if: github.event_name == 'pull_request'
197+
steps:
198+
- uses: actions/checkout@v4
199+
- uses: dtolnay/rust-toolchain@stable
200+
- uses: Swatinem/rust-cache@v2
201+
with:
202+
shared-key: build
203+
- uses: shivammathur/setup-php@v2
204+
with:
205+
php-version: "8.4"
206+
tools: composer
207+
- name: Install mold linker
208+
run: sudo apt-get install -y mold
209+
- name: Configure mold
210+
run: |
211+
mkdir -p .cargo
212+
echo '[target.x86_64-unknown-linux-gnu]' >> .cargo/config.toml
213+
echo 'rustflags = ["-C", "link-arg=-fuse-ld=mold"]' >> .cargo/config.toml
214+
- name: Build release binary
215+
run: cargo build --release
216+
- name: Check gh-pages branch exists
217+
id: check-gh-pages
218+
run: |
219+
if git ls-remote --exit-code --heads origin gh-pages > /dev/null 2>&1; then
220+
echo "exists=true" >> "$GITHUB_OUTPUT"
221+
else
222+
echo "exists=false" >> "$GITHUB_OUTPUT"
223+
echo "⚠️ gh-pages branch does not exist yet — skipping memory benchmark comparison"
224+
fi
225+
- name: Measure memory usage
226+
if: steps.check-gh-pages.outputs.exists == 'true'
227+
run: python3 benches/memory_usage.py --binary target/release/phpantom_lsp | tee memory_output.json
228+
- name: Compare against baseline
229+
if: steps.check-gh-pages.outputs.exists == 'true'
230+
uses: benchmark-action/github-action-benchmark@v1
231+
with:
232+
name: PHPantom Memory Usage
233+
tool: customSmallerIsBetter
234+
output-file-path: memory_output.json
235+
gh-pages-branch: gh-pages
236+
benchmark-data-dir-path: dev/memory
237+
auto-push: false
238+
github-token: ${{ secrets.GITHUB_TOKEN }}
239+
comment-on-alert: true
240+
alert-threshold: "130%"
241+
fail-on-alert: true
242+
alert-comment-cc-users: "@AJenbo"

0 commit comments

Comments
 (0)