v3.1
[3.1] - 21.03.2026
The "Micro-Optimizations & Memory Safety" update. This version introduces targeted performance improvements to internal state checks, cleans up the codebase by removing duplicates, and resolves a critical memory leak in asynchronous broadcast queues.
Added
- Advanced Test Scenarios:
- Introduced
test_exception_handling_in_context_managerto guaranteewith/async withblocks strictly release locks upon raised exceptions. - Added
test_writer_downgrade_wakes_readersto validate atomic downgrades automatically signaling sleeping readers. - Embedded
test_task_cancellation_during_waitinAsyncRWLockto ensure task cancellations (CancelledError) cleanly pop from queues without leaving zombie waiters. - Appended
test_massive_notify_all_cache_stampede_resiliencefor Conditions to stress-test 100+ concurrent wake-ups with zero drop rates.
- Introduced
- Automated Benchmark Orchestration & Visualization:
- Introduced
collect_benchmark_data_script.pyto silently execute benchmarks and export pure data as structured JSON files. - Created
benchmark_figure_script.pywith aBenchmarkOrchestratorto automatically trigger data collection across multiple Python interpreters (Standard, Free-Threading GIL On, Free-Threading GIL Off) viasubprocess. - Implemented an advanced
BenchmarkPlotterusingpandasandseabornthat dynamically ingests JSON results and renders highly detailed, adaptive, and transparent SVG charts optimized for GitHub themes.
- Introduced
- Documentation & Internationalization:
- Embedded the newly generated, highly detailed SVG benchmark graphics directly into the README files to visually demonstrate the massive performance leaps.
- Introduced full Russian language support (
README_ru.md), providing a meticulous and technically accurate translation of the entire documentation. - Expanded the "Performance and Benchmark Results" sections to include comprehensive testing methodology and hardware environment details for absolute transparency.
Updated
- Reentrant Lock Fast-Paths (Thread & Async):
- Optimized the core
_can_readand_can_writechecks for all Reentrant lock variations. - Previously, these locks constantly called expensive system-level functions (
threading.get_ident()orasyncio.current_task()) even when no writer was active. We now bypass these calls entirely when the lock is free. - This results in a significant speed boost for Reentrant locks during heavy read workloads.
- Optimized the core
- O(1) Efficiency for Downgraded Locks:
- Improved the cleanup process inside the
.write.release()method for locks that have been downgraded. - Replaced a double condition check (
if item in set: set.remove(item)) with a more efficient, single-steptry/exceptblock. This reduces the computational overhead of hash lookups.
- Improved the cleanup process inside the
- Unified Core Logic with State-Machine Mixins:
- Extracted the core scheduling algorithms (like
_can_readand_can_write) that were identical across Thread and Async lock variations. - Created a new
mixins.pymodule to house these shared behaviors. - This change removes hundreds of lines of duplicated code, making the library much easier to maintain without mixing OS-level Threads and Asyncio tasks.
- Extracted the core scheduling algorithms (like
- Modular Benchmark Framework & Data Handlers:
- Completely overhauled the
benchmarksdirectory to strictly follow DRY principles using Object-Oriented design. - Introduced
benchmark_base.pycontainingBenchmarkerBaseandAsyncBenchmarkerBasetemplate classes. - Extracted all performance scenarios into a centralized
benchmark_scenario.pymodule (IOBoundScenario,CPUBoundScenario, etc.). - Advanced Data Handling: Replaced hardcoded console output with a Dependency Injection architecture (
BenchmarkDataHandlerandBenchmarkPrintHandler). This allows benchmark outputs to be easily captured as structural dictionaries (dict) for JSON/CSV reporting or natively printed to the console. - This drastically reduces boilerplate code and makes future performance testing highly extensible.
- Completely overhauled the
Fixed
- Critical Memory Leak in Async Wait Queues:
- Fixed a bug in
_AsyncWaitQueue.notify_all()that left completedasyncio.Futureobjects lingering in memory. - Added a strict
waiters.clear()step after broadcasting. This completely stops O(N) performance slowdowns and prevents memory usage from infinitely ballooning whennotify_all()is called frequently.
- Fixed a bug in