Skip to content

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Oct 13, 2025

Decorating methods with lru_cache causes a leak. Fixed as suggested in https://rednafi.com/python/lru-cache-on-methods/

This was present for a while, but was made worse in #1594 when we switched from lru_cache which has a default limit of 128 to cache which can grow without bounds. (h/t to @jessegrabowski who suggested the change)

This caused a failure downstream in PyMC in a test that checks for similar sort of leak.


📚 Documentation preview 📚: https://pytensor--1660.org.readthedocs.build/en/1660/

Calling `lru_cache` on instance methods causes a leak. Fixed as suggested in https://rednafi.com/python/lru-cache-on-methods/
@ricardoV94 ricardoV94 added the bug Something isn't working label Oct 13, 2025
Copy link
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

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

Great catch, very subtle bug.

Copy link

codecov bot commented Oct 14, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.56%. Comparing base (db5178b) to head (7a90d3d).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pytensor/graph/rewriting/basic.py 66.66% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (66.66%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1660      +/-   ##
==========================================
- Coverage   81.56%   81.56%   -0.01%     
==========================================
  Files         242      242              
  Lines       53818    53819       +1     
  Branches     9485     9485              
==========================================
  Hits        43899    43899              
- Misses       7430     7431       +1     
  Partials     2489     2489              
Files with missing lines Coverage Δ
pytensor/graph/rewriting/basic.py 72.19% <66.66%> (-0.06%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants