Skip to content

perf(asgi): remove per-request fresh event-loop creation - #83

Merged
ZhuchkaTriplesix merged 2 commits into
devfrom
issue-73-asgi-no-fresh-loop
Apr 27, 2026
Merged

perf(asgi): remove per-request fresh event-loop creation#83
ZhuchkaTriplesix merged 2 commits into
devfrom
issue-73-asgi-no-fresh-loop

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Summary

  • replace per-request asyncio.run in the ASGI blocking bridge with a reused thread-local event loop
  • preserve request behavior while reducing fixed bridge overhead and executor churn
  • add regression test that fails if asyncio.run is used again on the blocking path

Test plan

  • uv run pytest tests/test_asgi_internals.py tests/test_asgi_stress.py tests/test_asgi.py

Benchmark notes

  • before: one fresh event loop allocation per request in _run_handle_rsgi_blocking
  • after: lazy single loop allocation per worker thread, reused across requests

Closes #73

Replace per-request asyncio.run loop creation with a lazily initialized thread-local loop to reduce ASGI bridge fixed overhead under load.
Add regression coverage that fails if the blocking bridge path reintroduces per-request asyncio.run, with explicit loop cleanup for test hygiene.

@ZhuchkaTriplesix ZhuchkaTriplesix left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

123

@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit 23d3d70 into dev Apr 27, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(asgi): remove per-request fresh event-loop creation in bridge worker path

1 participant