Skip to content

Measure Linux benchmark peak RSS with GNU time - #165

Merged
lolpack merged 2 commits into
lolpack:mainfrom
sharkdp:codex/linux-peak-rss
Nov 6, 2026
Merged

lolpack merged 2 commits into
lolpack:mainfrom
sharkdp:codex/linux-peak-rss

Conversation

@sharkdp

@sharkdp sharkdp commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #161.

Use GNU time on Linux to collect peak RSS when the type-checker exits (the OOM watcher still uses /proc/<pid>/status for querying while the process is still running).

I ran a benchmark for each type-checker on "cerify". Each cell shows min..max peak RSS in MiB for five benchmarking runs. Standalone GNU time is used for comparison. As we can tell from this table, the new ("After") results are closed to the time measurements, especially for the fast-running type checkers. The previous implementation could miss as much as 13 MiB, or 20% of the peak RSS (see e.g. the "min" times in the Pyrefly or ty rows):

Checker Before (/proc polling) After (GNU time) Standalone GNU time
Pyright 1.1.414 141.6..142.5 141.8..142.5 141.8..142.6
Pyrefly 1.4.0 52.4..64.6 64.3..64.8 64.1..64.6
ty 0.0.96 37.4..41.9 46.9..47.6 46.9..47.4
mypy 2.4.0 114.8..115.3 114.4..115.2 114.8..115.2
Zuban 0.10.1 26.8..27.6 32.9..33.2 32.9..33.5

@lolpack

lolpack commented Nov 5, 2026

Copy link
Copy Markdown
Owner

@sharkdp It looks like ru_maxrss includes the parent's high-water RSS from before exec, so the harness's own memory leaks into the result. Could you measure through GNU /usr/bin/time -f %M on Linux, as the macOS path does, so the checker starts from a small process? I'll rerun the experiment on the updated PR.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The timing test does not assert peak RSS, leaving discarded values or incorrect unit conversions undetected and the memory-measurement regression unprotected.

1 open issue
What changed in this PR

This PR addresses #161 by measuring Linux type-checker peak RSS at process exit, avoiding missed memory peaks from polling.

Changes:

  • Use blocking wait4() to collect exit status and peak RSS on Linux.
  • Retain /proc polling only for memory-limit enforcement.
  • Update the timing test to verify Linux uses a blocking wait.
File Description
typecheck_benchmark/​daily_runner.py Collect peak RSS with wait4() and separate memory-limit monitoring.
tests/​test_typecheck_benchmark_timing.py Verify blocking wait4() behavior on Linux.

Review effort: Balanced

Comment on lines +38 to +46
if sys.platform == "linux":
with patch("os.wait4", wraps=os.wait4) as wait4:
run_process_with_timeout(
[sys.executable, "-S", "-c", "pass"],
cwd=tmp_path, timeout=30, capture_output=False,
)
wait4.assert_called_once()
assert wait4.call_args.args[1] == 0 # Blocking wait.
return
@sharkdp sharkdp changed the title Measure Linux benchmark peak RSS with wait4 Measure Linux benchmark peak RSS with GNU time Nov 5, 2026
@sharkdp

sharkdp commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Ok, updated to use GNU time. I also edited the PR description with the updated experiment.

@lolpack lolpack left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timing was largely unaffected from this change, but still worth landing for better resiliency and precision. https://github.com/lolpack/type_coverage_py/actions/runs/42083592710

@lolpack
lolpack merged commit 3fbf122 into lolpack:main Nov 6, 2026
2 checks passed
lolpack added a commit that referenced this pull request Nov 6, 2026
The runner measures Linux peak memory with /usr/bin/time (#165). The
ubuntu-latest image ships it today, but if a future image dropped it every
checker would fail to launch and the whole run would crash. Installing it
explicitly is a no-op while it is present.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Peak memory usage measurements may be inaccurate or missing on Linux

3 participants