Skip to content

perf(response): replace protocol.getattr with call_method1 to avoid PyMethodObject allocations (#251) - #258

Merged
ZhuchkaTriplesix merged 1 commit into
devfrom
issue-251-protocol-call-method
Oct 18, 2026
Merged

ZhuchkaTriplesix merged 1 commit into
devfrom
issue-251-protocol-call-method

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Closes #251

Summary of Changes

  • Replaced all instances of p.getattr("response_*")?.call1(...) on the RSGI protocol with p.call_method1("response_*", ...) across src/response.rs:
    • send_with_headers (response_bytes)
    • send_empty_with_header_pairs (response_empty)
    • send_str_sync (response_str)
    • send_pybytes_sync (response_bytes)
    • send_bytes_sync (response_bytes)
    • send_empty_sync (response_empty)
    • send_with_headers_sync (response_empty, response_bytes)
    • send_405_method_not_allowed_sync (response_bytes)
    • send_429_rate_limited_sync (response_bytes)
    • send_head_simple_sync (response_empty)
  • This invokes CPython's vectorcall / fast method calling directly without allocating a temporary PyMethodObject on every response sent by the framework.
  • Formatted with cargo fmt, verified with cargo clippy, and tested with targeted test suites (all 29 pytest tests + 36 Rust unit tests pass).

@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit c2a14c1 into dev Oct 18, 2026
17 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.

1 participant