Skip to content

perf: protocol.getattr allocates PyMethodObject on every response in response.rs #251

Closed

Description

@ZhuchkaTriplesix

Where: src/response.rs:199, 230, 247, 260, 275 (send_str_sync, send_bytes_sync, send_empty_sync, send_with_headers_sync, etc.).

Currently, sending any response calls:

p.getattr("response_str")?.call1((status, h, text))?;
p.getattr("response_bytes")?.call1((status, h, body))?;
p.getattr("response_empty")?.call1((status, h))?;

In CPython, p.getattr("...") resolves the descriptor and allocates a temporary bound method (PyMethodObject) on the heap for every response.

Fix direction:
Use p.call_method1("response_str", (status, h, text))? (and equivalent call_method1 calls). This invokes the CPython vectorcall / fast method call API directly without allocating method objects.

Activity

  1. added
    enhancement
    on Oct 18, 2026
  2. added a commit that references this issue on Oct 18, 2026
  3. ZhuchkaTriplesix commented on Oct 18, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Resolved in PR #258

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions