Skip to content

Commit bf4df9e

Browse files
committed
add separate CI job for memory usage stats
1 parent 333191b commit bf4df9e

File tree

5 files changed

+112
-8
lines changed

5 files changed

+112
-8
lines changed

.github/workflows/mypy_primer.yaml

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ jobs:
4848

4949
- name: Run mypy_primer
5050
shell: bash
51-
env:
52-
TY_MEMORY_REPORT: mypy_primer
5351
run: |
5452
cd ruff
5553
@@ -101,3 +99,75 @@ jobs:
10199
with:
102100
name: pr-number
103101
path: pr-number
102+
103+
memory_usage:
104+
name: Run memory statistics
105+
runs-on: depot-ubuntu-22.04-32
106+
timeout-minutes: 20
107+
steps:
108+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
109+
with:
110+
path: ruff
111+
fetch-depth: 0
112+
persist-credentials: false
113+
114+
- name: Install the latest version of uv
115+
uses: astral-sh/setup-uv@bd01e18f51369d5a26f1651c3cb451d3417e3bba # v6.3.1
116+
117+
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
118+
with:
119+
workspaces: "ruff"
120+
121+
- name: Install Rust toolchain
122+
run: rustup show
123+
124+
- name: Run mypy_primer
125+
shell: bash
126+
env:
127+
TY_MAX_PARALLELISM: 1 # for deterministic memory numbers
128+
TY_MEMORY_REPORT: mypy_primer
129+
run: |
130+
cd ruff
131+
132+
echo "Enabling mypy primer specific configuration overloads (see .github/mypy-primer-ty.toml)"
133+
mkdir -p ~/.config/ty
134+
cp .github/mypy-primer-ty.toml ~/.config/ty/ty.toml
135+
136+
PRIMER_SELECTOR="$(paste -s -d'|' crates/ty_python_semantic/resources/primer/memory.txt)"
137+
138+
echo "new commit"
139+
git rev-list --format=%s --max-count=1 "$GITHUB_SHA"
140+
141+
MERGE_BASE="$(git merge-base "$GITHUB_SHA" "origin/$GITHUB_BASE_REF")"
142+
git checkout -b base_commit "$MERGE_BASE"
143+
echo "base commit"
144+
git rev-list --format=%s --max-count=1 base_commit
145+
146+
cd ..
147+
148+
echo "Project selector: $PRIMER_SELECTOR"
149+
# Allow the exit code to be 0 or 1, only fail for actual mypy_primer crashes/bugs
150+
uvx \
151+
--from="git+https://github.com/hauntsaninja/mypy_primer@e5f55447969d33ae3c7ccdb183e2a37101867270" \
152+
mypy_primer \
153+
--repo ruff \
154+
--type-checker ty \
155+
--old base_commit \
156+
--new "$GITHUB_SHA" \
157+
--project-selector "/($PRIMER_SELECTOR)\$" \
158+
--output concise \
159+
--debug > mypy_primer_memory.diff || [ $? -eq 1 ]
160+
161+
# Output diff with ANSI color codes
162+
cat mypy_primer_memory.diff
163+
164+
# Remove ANSI color codes before uploading
165+
sed -ie 's/\x1b\[[0-9;]*m//g' mypy_primer_memory.diff
166+
167+
echo ${{ github.event.number }} > pr-number
168+
169+
- name: Upload diff
170+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
171+
with:
172+
name: mypy_primer_memory_diff
173+
path: mypy_primer_memory.diff

.github/workflows/mypy_primer_comment.yaml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,28 @@ jobs:
4545
if_no_artifact_found: ignore
4646
allow_forks: true
4747

48+
- uses: dawidd6/action-download-artifact@20319c5641d495c8a52e688b7dc5fada6c3a9fbc # v8
49+
name: "Download mypy_primer memory results"
50+
id: download-mypy_primer_memory_diff
51+
if: steps.pr-number.outputs.pr-number
52+
with:
53+
name: mypy_primer_memory_diff
54+
workflow: mypy_primer.yaml
55+
pr: ${{ steps.pr-number.outputs.pr-number }}
56+
path: pr/mypy_primer_memory_diff
57+
workflow_conclusion: completed
58+
if_no_artifact_found: ignore
59+
allow_forks: true
60+
4861
- name: Generate comment content
4962
id: generate-comment
50-
if: steps.download-mypy_primer_diff.outputs.found_artifact == 'true'
63+
if: ${{ steps.download-mypy_primer_diff.outputs.found_artifact == 'true' && steps.download-mypy_primer_memory_diff.outputs.found_artifact == 'true' }}
5164
run: |
5265
# Guard against malicious mypy_primer results that symlink to a secret
5366
# file on this runner
54-
if [[ -L pr/mypy_primer_diff/mypy_primer.diff ]]
67+
if [[ -L pr/mypy_primer_diff/mypy_primer.diff ]] || [[ -L pr/mypy_primer_memory_diff/mypy_primer_memory.diff ]]
5568
then
56-
echo "Error: mypy_primer.diff cannot be a symlink"
69+
echo "Error: mypy_primer.diff and mypy_primer_memory.diff cannot be a symlink"
5770
exit 1
5871
fi
5972
@@ -74,6 +87,18 @@ jobs:
7487
echo 'No ecosystem changes detected ✅' >> comment.txt
7588
fi
7689
90+
if [ -s "pr/mypy_primer_memory_diff/mypy_primer_memory.diff" ]; then
91+
echo '<details>' >> comment.txt
92+
echo '<summary>Memory usage changes were detected when running on open source projects</summary>' >> comment.txt
93+
echo '' >> comment.txt
94+
echo '```diff' >> comment.txt
95+
cat pr/mypy_primer_memory_diff/mypy_primer_memory.diff >> comment.txt
96+
echo '```' >> comment.txt
97+
echo '</details>' >> comment.txt
98+
else
99+
echo 'No memory usage changes detected ✅' >> comment.txt
100+
fi
101+
77102
echo 'comment<<EOF' >> "$GITHUB_OUTPUT"
78103
cat comment.txt >> "$GITHUB_OUTPUT"
79104
echo 'EOF' >> "$GITHUB_OUTPUT"

crates/ty/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ impl MainLoop {
296296
tracing::warn!("No python files found under the given path(s)");
297297
}
298298

299+
// TODO: We should have an official flag to silence workspace diagnostics.
300+
if std::env::var("TY_MEMORY_REPORT").as_deref() == Ok("mypy_primer") {
301+
return Ok(ExitStatus::Success);
302+
}
303+
299304
let mut stdout = stdout().lock();
300305

301306
if result.is_empty() {

crates/ty_project/src/db.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ impl SalsaMemoryDump {
324324
struct DisplayShort<'a>(&'a SalsaMemoryDump);
325325

326326
fn round_memory(total: usize) -> usize {
327-
// Round the number to the nearest power of 1.1. This gives us a
328-
// 5% threshold before the memory usage number is considered to have
327+
// Round the number to the nearest power of 1.05. This gives us a
328+
// 2.5% threshold before the memory usage number is considered to have
329329
// changed.
330330
//
331331
// TODO: Small changes in memory usage may cause the number to be rounded
@@ -334,7 +334,7 @@ impl SalsaMemoryDump {
334334
// over time that are unrelated to the current change. Ideally we could compare
335335
// the exact numbers across runs and compute the difference, but we don't have
336336
// the infrastructure for that currently.
337-
const BASE: f64 = 1.1;
337+
const BASE: f64 = 1.05;
338338
BASE.powf(bytes_to_mb(total).log(BASE).round()) as usize
339339
}
340340

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
flake8
2+
sphinx
3+
prefect
4+
trio

0 commit comments

Comments
 (0)