Add optional uvloop support for better event loop performance#13047
Add optional uvloop support for better event loop performance#13047lukasmasuch merged 5 commits intodevelopfrom
Conversation
✅ PR preview is ready!
|
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
| # orjson speeds up large plotly figure processing by 5-10x: | ||
| "orjson>=3.5.0", | ||
| # uvloop speeds up the event loop: | ||
| "uvloop>=0.15.1; sys_platform != 'win32' and (sys_platform != 'cygwin' and platform_python_implementation != 'PyPy')", # noqa: E501 |
There was a problem hiding this comment.
The environment marker platform_python_implementation should be changed to python_implementation, which is the correct marker name in setuptools. The corrected dependency specification would be:
"uvloop>=0.15.1; sys_platform != 'win32' and (sys_platform != 'cygwin' and python_implementation != 'PyPy')"
This ensures proper compatibility checking when the package is installed.
| "uvloop>=0.15.1; sys_platform != 'win32' and (sys_platform != 'cygwin' and platform_python_implementation != 'PyPy')", # noqa: E501 | |
| "uvloop>=0.15.1; sys_platform != 'win32' and (sys_platform != 'cygwin' and python_implementation != 'PyPy')", # noqa: E501 |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
Pull Request Overview
This PR adds optional support for uvloop, an ultra-fast drop-in replacement for Python's built-in asyncio event loop. When uvloop is installed, Streamlit will automatically use it to improve event loop performance. This is a preparation step for PR #12772.
Key Changes:
- Automatic uvloop activation when installed (non-Windows platforms only)
- Graceful fallback to default event loop if uvloop is unavailable or fails to install
- Comprehensive test coverage for various scenarios (available, missing, Windows, running loop)
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| lib/streamlit/web/bootstrap.py | Implements _maybe_install_uvloop() function to conditionally install uvloop as the event loop policy |
| lib/tests/streamlit/web/bootstrap_test.py | Adds test suite for uvloop installation scenarios (available, missing, Windows, running event loop) |
| lib/setup.py | Adds new "performance" optional dependency group containing uvloop (with platform markers) and orjson |
| lib/test-requirements.txt | Adds uvloop>=0.15.1 to test dependencies for testing the integration |
| mypy.ini | Adds mypy configuration to ignore missing uvloop type stubs |
Describe your changes
Adds optional support for using uvloop as event loop. uvloop is an ultra-fast, drop-in replacement of the built-in asyncio event loop. This feature will get activated by having uvloop installed.
This change is a preparation for #12772
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.