Skip to content

test: Add memory usage benchmarks#1737

Open
ferbetanzo wants to merge 4 commits into
mainfrom
fb/benchmark-mem-usage
Open

test: Add memory usage benchmarks#1737
ferbetanzo wants to merge 4 commits into
mainfrom
fb/benchmark-mem-usage

Conversation

@ferbetanzo
Copy link
Copy Markdown
Contributor

@ferbetanzo ferbetanzo commented May 14, 2026

Includes:

  • New compile_and_get_peak_memory util to get the memory used when compiling a guppy function using tracemalloc.get_traced_memory().
  • The *_compile tests in the big array, many ctrl flow and queue suites now report used peak memory.
  • Adds a new test_mem_usage suite that benchmarks mem usage of single and multiple compilations of guppy funcs that use array and list comprehensions.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

🐰 Bencher Report

Branchfb/benchmark-mem-usage
TestbedLinux
Click to view all benchmark results
Benchmarkcompile_membytes x 1e3hugr_bytesBenchmark Result
bytes x 1e3
(Result Δ%)
Upper Boundary
bytes x 1e3
(Limit %)
hugr_nodesBenchmark Result
nodes
(Result Δ%)
Upper Boundary
nodes
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
21,346.58 x 1e3📈 view plot
🚷 view threshold
158.80 x 1e3
(+0.02%)Baseline: 158.77 x 1e3
160.36 x 1e3
(99.03%)
📈 view plot
🚷 view threshold
6,641.00
(0.00%)Baseline: 6,641.00
6,707.41
(99.01%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
3,394.13 x 1e3📈 view plot
🚷 view threshold
27.54 x 1e3
(+0.01%)Baseline: 27.53 x 1e3
27.81 x 1e3
(99.02%)
📈 view plot
🚷 view threshold
1,074.00
(0.00%)Baseline: 1,074.00
1,084.74
(99.01%)
tests/benchmarks/test_mem_usage.py::test_mem_compile_multiple[array]📈 view plot
🚷 view threshold
7,392.26 x 1e3
tests/benchmarks/test_mem_usage.py::test_mem_compile_multiple[list]📈 view plot
🚷 view threshold
4,937.26 x 1e3
tests/benchmarks/test_mem_usage.py::test_mem_compile_multiple[qubit]📈 view plot
🚷 view threshold
408.69 x 1e3
tests/benchmarks/test_mem_usage.py::test_mem_compile_once[array]📈 view plot
🚷 view threshold
1,110.32 x 1e3
tests/benchmarks/test_mem_usage.py::test_mem_compile_once[list]📈 view plot
🚷 view threshold
821.13 x 1e3
tests/benchmarks/test_mem_usage.py::test_mem_compile_once[qubit]📈 view plot
🚷 view threshold
96.86 x 1e3
tests/benchmarks/test_queue_push_pop.py::test_queue_push_benchmark_compile📈 view plot
🚷 view threshold
1,707.83 x 1e3📈 view plot
🚷 view threshold
10.90 x 1e3
(-0.06%)Baseline: 10.91 x 1e3
11.02 x 1e3
(98.96%)
📈 view plot
🚷 view threshold
308.00
(0.00%)Baseline: 308.00
311.08
(99.01%)
tests/benchmarks/test_queue_push_pop.py::test_queue_push_pop_benchmark_compile📈 view plot
🚷 view threshold
2,203.95 x 1e3📈 view plot
🚷 view threshold
14.84 x 1e3
(+0.01%)Baseline: 14.84 x 1e3
14.99 x 1e3
(99.02%)
📈 view plot
🚷 view threshold
435.00
(0.00%)Baseline: 435.00
439.35
(99.01%)
🐰 View full continuous benchmarking report in Bencher

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.50%. Comparing base (48f32b9) to head (ada480f).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 14, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing fb/benchmark-mem-usage (ada480f) with main (cd38448)

Open in CodSpeed

@ferbetanzo ferbetanzo marked this pull request as ready for review May 14, 2026 15:00
@ferbetanzo ferbetanzo requested a review from a team as a code owner May 14, 2026 15:00
@ferbetanzo ferbetanzo requested a review from qartik May 14, 2026 15:00
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"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Skipping the memory usage benchmarks in the codspeed execution since we're tracking those metrics with bencher.

@maximilianruesch maximilianruesch changed the title chore: add memory usage benchmarks test: Add memory usage benchmarks May 14, 2026
@qartik qartik requested a review from Copilot May 14, 2026 15:26
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_memory test utility to collect peak traced memory during compilation.
  • Extended several existing compile benchmarks to record benchmark.extra_info["memory"] and export it as compile_mem in Bencher JSON.
  • Introduced a new test_mem_usage benchmark 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.

Comment thread tests/util.py Outdated
Comment thread tests/util.py Outdated
Comment thread tests/bencher.py
Comment thread pyproject.toml Outdated
Comment thread .github/workflows/benchmarks_pr.yml
Comment thread tests/benchmarks/test_mem_usage.py
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Comment thread tests/util.py
Comment on lines +53 to +61
try:
gc.disable()
for _ in range(n_compilations):
guppy_fn.compile()
_, peak = tracemalloc.get_traced_memory()
gc.enable()
_ = gc.collect()
return peak
finally:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ferbetanzo waiting for this to be resolved as well before taking a closer look.

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.

4 participants