v3.2
[3.2] - 22.03.2026
The "Absolute Speed & Memory Safety" update. This version strictly prioritizes raw execution speed by reversing the DRY-oriented mixin architecture, introduces O(1) memory optimizations for thread state downgrades, completely eliminates a critical memory leak in async task tracking via weak references, and refines type hinting for standard adapters.
Updated
- Removal of State-Machine Mixins (
mixins.py):- Completely removed the
mixins.pymodule that was introduced in version 3.1. - Re-inlined all core scheduling algorithms (
_can_read,_can_write,_acquire_read_core, etc.) directly back into their respective Thread and Async lock classes. - Reasoning: While the mixin architecture made the codebase significantly cleaner by following DRY principles, the Method Resolution Order (MRO) indirection and the overhead of extra class hierarchy jumps caused a ~2-3% performance penalty in highly concurrent
RWLockandRWConditionworkloads. In a low-level concurrency primitive library, raw execution speed inherently outweighs code aesthetics.
- Completely removed the
- O(1) Memory Optimization for Thread Downgrades:
- Replaced the
_downgraded_threadshash set with a single_downgraded_thread_idvariable inRWLockWriterProxy. - Since a write lock is strictly exclusive, only one thread can ever hold and downgrade it at any given time. Maintaining a dynamic set was structurally redundant and incurred unnecessary allocation overhead.
- Replaced the
Fixed
- Memory Leak Prevention in Async Downgrades:
- Upgraded the
_downgraded_taskstracker inAsyncRWLockWriterProxyto utilize aweakref.WeakSetinstead of a standardset. asyncio.Taskobjects are highly volatile and frequently destroyed. Keeping strong references inside the lock proxy could lead to severe memory leaks (zombie tasks). TheWeakSetguarantees they are cleanly garbage-collected by Python.
- Upgraded the
- Standard Adapter Type Hinting:
- Corrected the
__init__constructor type hints for standardConditionandAsyncConditionadapters. - They now correctly accept the
LockableandAsyncLockableprotocols, fixing an issue where they falsely restricted inputs to proxy-basedRWLockBasestructures, ignoring standard standard library locks.
- Corrected the