Skip to content

perf: More efficient calling frame detection#1884

Merged
maximilianruesch merged 1 commit into
mainfrom
mr/perf/calling-frame-detection
Jun 18, 2026
Merged

perf: More efficient calling frame detection#1884
maximilianruesch merged 1 commit into
mainfrom
mr/perf/calling-frame-detection

Conversation

@maximilianruesch

Copy link
Copy Markdown
Collaborator

Using inspect.getmodule is overkill when all you are trying to retrieve is the name of the module (you can access that through the file-global __name__ as well). At the same time, inspect.getmodule accesses the file cache of the Python interpreter, potentially doing a lot of IO. During tracing workloads, calling frame detection is run for most expressions for purposes of nice error messages, and thus the inspect.getmodule is called in a rather hot loop. Any improvements here are vital for tracing performance.

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchmr/perf/calling-frame-detection
TestbedLinux
Click to view all benchmark results
Benchmarkhugr_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
154.02 x 1e3
(0.00%)Baseline: 154.02 x 1e3
155.56 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
6,630.00
(0.00%)Baseline: 6,630.00
6,696.30
(99.01%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
27.71 x 1e3
(0.00%)Baseline: 27.71 x 1e3
27.99 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
1,051.00
(0.00%)Baseline: 1,051.00
1,061.51
(99.01%)
tests/benchmarks/test_queue_push_pop.py::test_queue_push_benchmark_compile📈 view plot
🚷 view threshold
10.09 x 1e3
(0.00%)Baseline: 10.09 x 1e3
10.19 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
301.00
(0.00%)Baseline: 301.00
304.01
(99.01%)
tests/benchmarks/test_queue_push_pop.py::test_queue_push_pop_benchmark_compile📈 view plot
🚷 view threshold
13.69 x 1e3
(-0.01%)Baseline: 13.70 x 1e3
13.83 x 1e3
(99.00%)
📈 view plot
🚷 view threshold
420.00
(0.00%)Baseline: 420.00
424.20
(99.01%)
🐰 View full continuous benchmarking report in Bencher

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.84%. Comparing base (e2c7014) to head (2c2ecb3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1884   +/-   ##
=======================================
  Coverage   92.84%   92.84%           
=======================================
  Files         146      146           
  Lines       13822    13822           
=======================================
  Hits        12833    12833           
  Misses        989      989           

☔ View full report in Codecov by Harness.
📢 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

codspeed-hq Bot commented Jun 18, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 17.56%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 10 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
test_circuit_comptime_compile 1.7 s 1.5 s +17.56%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing mr/perf/calling-frame-detection (2c2ecb3) with main (e2c7014)

Open in CodSpeed

@maximilianruesch maximilianruesch marked this pull request as ready for review June 18, 2026 09:27
@maximilianruesch maximilianruesch requested a review from a team as a code owner June 18, 2026 09:27
@maximilianruesch maximilianruesch requested review from acl-cqc and nicolaassolini-qntm and removed request for acl-cqc June 18, 2026 09:27

@nicolaassolini-qntm nicolaassolini-qntm 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.

17% faster, nice :shipit:

@maximilianruesch maximilianruesch added this pull request to the merge queue Jun 18, 2026
Merged via the queue into main with commit 487a8ac Jun 18, 2026
13 checks passed
@maximilianruesch maximilianruesch deleted the mr/perf/calling-frame-detection branch June 18, 2026 10:44
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.

3 participants