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.
Where:
src/dispatch.rs:703-737(PooledBuffer,src/buffer_pool.rs).PyBytesfrom Granian and is copied byte-for-byte into aPooledBuffer(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 theshould_read_body == falsepath (:736), which is wasted pool churn since nothing is ever written to it.Fix direction: avoid the copy where possible (e.g.
PyBackedBytes/zero-copy borrow of thePyBytesbuffer), skipPooledBuffer::new()entirely whenshould_read_bodyis false, and reconsider whether a thread-local pool is the right structure given task migration.