misc: Thread-safe cache rewrite
Rewrites memoized_meth and memoized_generator for concurrency, as well as dropping the legacy memoized_func in favor of functools.cache. Also adds a global lock for the symbol cache allowing thread-safe Symbol construction and cache manipulation.
The memoized_meth decorator now stores one cache per thread, whereas memoized_generator stores a single cache for a given method (though there may still be misses if the cache is initialized concurrently). This means neither method cache has a call-once guarantee.
Memoized generators block for the initial call of the generator function and construct a thread-safe version of itertools.tee, which allows for concurrent iteration (but blocks when iterating elements that are not yet in the buffer). After the source generator is consumed, there is no blocking and subsequently threads can iterate the buffer in parallel (see SafeTee in tools.memoization).
Codecov Report
:x: Patch coverage is 89.13043% with 25 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 87.52%. Comparing base (cd9058b) to head (8bb95f2).
:warning: Report is 145 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #2683 +/- ##
==========================================
+ Coverage 78.59% 87.52% +8.92%
==========================================
Files 245 245
Lines 49089 49230 +141
Branches 4322 4322
==========================================
+ Hits 38582 43087 +4505
+ Misses 9714 5408 -4306
+ Partials 793 735 -58
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.