-
Notifications
You must be signed in to change notification settings - Fork 3
Cython optimization #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…cessing to improve throughput, including benchmarks and a Python fallback.
…ing and benchmarking artifacts.
…roduce performance benchmarks.
…hon fallback, and include benchmarks.
…/Python fallback, and add `__all__` declarations.
…ark commands to include specific file patterns and timeout options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces Cython-based performance optimizations and a comprehensive benchmarking framework for the python-redux project. The changes refactor core components to support both pure Python and Cython implementations, add extensive performance benchmarks, and include profiling tools.
Key Changes:
- Added Cython-optimized implementations of
StoreandAutorunclasses with a fallback mechanism to pure Python - Introduced benchmark suites for measuring dispatch, autorun, and combined reducer performance
- Refactored code organization to separate pure Python implementations from Cython versions
- Updated development dependencies and configuration to support Cython compilation and benchmarking
Reviewed changes
Copilot reviewed 41 out of 52 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
redux/main.py |
Refactored to conditionally import Cython or Python implementations of Store based on availability |
redux/_store_py.py |
New file containing the pure Python Store implementation (moved from main.py) |
redux/_store_core.pyx |
New Cython implementation of Store and Autorun classes for performance |
redux/_store_core.pyi |
Type stub file for the Cython Store implementation |
redux/autorun.py |
Refactored to conditionally import Cython or Python Autorun implementations |
redux/_autorun_py.py |
New file containing the pure Python Autorun implementation |
redux/combine_reducers.py |
Refactored to conditionally import Cython or Python combine_reducers |
redux/_combine_reducers_py.py |
New file containing the pure Python combine_reducers implementation |
redux/_combine_reducers.pyx |
New Cython implementation of combine_reducers |
redux/_combine_reducers.pyi |
Type stub file for the Cython combine_reducers |
setup.py |
New build configuration for Cython extensions |
pyproject.toml |
Added Cython and pytest-benchmark dependencies, updated linter and type checker configurations |
benchmarks/bench_dispatch.py |
New comprehensive benchmark suite for Store dispatch operations |
profile_optimization.py |
New profiling script for analyzing performance with heavy subscriber loads |
tests/*.py |
Updated ruff noqa directives and added compatibility fixes for Cython implementations |
todo_demo.py, demo.py |
Simplified ruff noqa directives |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| [tool.pyright] | ||
| exclude = ['typings', '.venv'] | ||
| extraPaths = ["/opt/homebrew/lib/python3.11/site-packages"] |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hardcoded absolute path to Homebrew's Python site-packages is machine-specific and will not work on other systems. Consider removing this configuration or using a relative/environment-based path instead.
| extraPaths = ["/opt/homebrew/lib/python3.11/site-packages"] |
|
|
||
| def __repr__(self): | ||
| return f'SubscribeEventCleanup(handler={self.handler})' | ||
| from libc.stdlib cimport malloc, free |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The malloc and free imports from libc.stdlib are declared but never used in this file. Consider removing these unused imports.
| from libc.stdlib cimport malloc, free |
|
|
||
| def default_autorun() -> type[Autorun]: | ||
| from redux.autorun import Autorun | ||
| from redux.autorun import Autorun # noqa: PLC0415 # noqa: PLC0415 |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The noqa comment # noqa: PLC0415 is duplicated. Remove the duplicate.
| from redux.autorun import Autorun # noqa: PLC0415 # noqa: PLC0415 | |
| from redux.autorun import Autorun # noqa: PLC0415 |
This pull request introduces a comprehensive Cython-based optimization and benchmarking framework for the
python-reduxproject. It adds high-performance Cython implementations for core Redux components, extensive benchmarks for measuring performance improvements, and profiling tools to analyze bottlenecks. The changes also include updates to development dependencies and configuration files to support benchmarking and Cython compilation.Cython Optimization and Benchmarking:
CYTHON_README.mdexplaining the Cython optimization phases, benchmark results, and instructions for building and running benchmarks.benchmarks/directory, covering a variety of performance-critical scenarios. [1] [2] [3] [4]profile_optimization.pyto measure and analyze performance with heavy subscriber loads, usingcProfileandpstats.Cython and Benchmarking Support:
pyproject.tomlto includecythonandpytest-benchmarkas development dependencies, and configuredruffandpyrightto support the new benchmarks and Cython files. [1] [2] [3] [4]Type Hints and Stubs:
.pyitype stub forredux/_combine_reducers.pyto improve type checking and editor support for the Cython-optimized reducer logic.Minor Cleanups:
demo.pyby removing unnecessary ruff disables.These changes collectively provide a robust infrastructure for evaluating and leveraging Cython optimizations in
python-redux, ensuring both high performance and maintainability.