Skip to content

perf: request body copied twice (PyBytes -> PooledBuffer), pool churns even when body is empty #219

Description

@ZhuchkaTriplesix

Where: src/dispatch.rs:703-737 (PooledBuffer, src/buffer_pool.rs).

  • The body arrives as PyBytes from Granian and is copied byte-for-byte into a PooledBuffer (extend_from_slice) — an extra full-body copy on every request that reads a body.
  • PooledBuffer::new() is called (and later returned to the thread-local pool) even on the should_read_body == false path (:736), which is wasted pool churn since nothing is ever written to it.
  • The pool is thread-local but the surrounding future can migrate across tokio worker threads, undermining the locality the pool is meant to provide.

Fix direction: avoid the copy where possible (e.g. PyBackedBytes/zero-copy borrow of the PyBytes buffer), skip PooledBuffer::new() entirely when should_read_body is false, and reconsider whether a thread-local pool is the right structure given task migration.

Activity

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions