test: Add memory usage benchmarks#1737
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1737 +/- ##
==========================================
- Coverage 93.51% 93.50% -0.02%
==========================================
Files 133 133
Lines 12766 12786 +20
==========================================
+ Hits 11938 11955 +17
- Misses 828 831 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| with: | ||
| mode: simulation | ||
| run: uv run pytest tests/ --codspeed -k "not executable" | ||
| run: uv run pytest tests/ --codspeed -k "not executable and not mem_compile" |
There was a problem hiding this comment.
Skipping the memory usage benchmarks in the codspeed execution since we're tracking those metrics with bencher.
There was a problem hiding this comment.
Pull request overview
Adds peak Python-allocation memory reporting to the benchmark suite by introducing a tracemalloc-based helper, wiring it into existing *_compile benchmarks, and exporting the metric to Bencher/CodSpeed workflows.
Changes:
- Added
compile_and_get_peak_memorytest utility to collect peak traced memory during compilation. - Extended several existing compile benchmarks to record
benchmark.extra_info["memory"]and export it ascompile_memin Bencher JSON. - Introduced a new
test_mem_usagebenchmark module and adjusted CI benchmark selection/threshold configuration.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
tests/util.py |
Adds compile_and_get_peak_memory helper using tracemalloc. |
tests/benchmarks/test_queue_push_pop.py |
Records compilation peak-memory extra metric for queue compile benchmarks. |
tests/benchmarks/test_mem_usage.py |
New memory-usage benchmark module for compiling small guppy programs. |
tests/benchmarks/test_ctrl_flow.py |
Records compilation peak-memory extra metric for ctrl-flow compile benchmark. |
tests/benchmarks/test_big_array.py |
Records compilation peak-memory extra metric for big-array compile benchmark. |
tests/bencher.py |
Exports the new memory extra metric as Bencher measure compile_mem. |
pyproject.toml |
Adds a global warning filter related to pytest-benchmark warnings. |
justfile |
Adds Bencher threshold checks for compile_mem. |
.github/workflows/benchmarks_pr.yml |
Excludes mem_compile tests from PR CodSpeed benchmark run. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try: | ||
| gc.disable() | ||
| for _ in range(n_compilations): | ||
| guppy_fn.compile() | ||
| _, peak = tracemalloc.get_traced_memory() | ||
| gc.enable() | ||
| _ = gc.collect() | ||
| return peak | ||
| finally: |
There was a problem hiding this comment.
@ferbetanzo waiting for this to be resolved as well before taking a closer look.
Includes:
compile_and_get_peak_memoryutil to get the memory used when compiling a guppy function usingtracemalloc.get_traced_memory().*_compiletests in the big array, many ctrl flow and queue suites now report used peak memory.test_mem_usagesuite that benchmarks mem usage of single and multiple compilations of guppy funcs that use array and list comprehensions.