Skip to content

new feature: support bounded buffered consumption of Python async file streams #8247

Description

@Xuanwo

Feature Description

Offer a bounded consumption path that amortizes native-to-Python async crossings without converting a sequential stream into repeated Range requests.

Problem and Solution

AsyncFile.read(size) calls the core read_buffer(size), which can return the current underlying network buffer rather than filling the requested size. Each returned fragment crosses the Tokio/asyncio boundary and creates a Python result. A large requested size therefore does not by itself amortize small transport fragments.

An explicit buffered reader or iterator could aggregate existing network buffers within Rust under a bounded byte budget. Reuse the current core reader rather than issuing an HTTP range for every application chunk.

Acceptance criteria:

  • Preserve the existing short-read, low-latency behavior of the default API.
  • Define buffering limits, EOF/error delivery, seek/ranges, and cancellation.
  • Compare natural sequential reads with the same consumer, recording actual request count, return-size histogram, CPU, first-byte latency, and memory.
  • Verify that fewer crossings do not come from unbounded buffering or withholding small responses indefinitely.

Additional Context

Related to #8159, which already tracks asynchronous listing crossings. This request concerns file-stream consumption.

AsyncFile.read; Core read_buffer

read(size) and transport chunk are different controls. The existing unchunked reader is the baseline; forcing a chunk changes request strategy. Fewer callbacks may primarily improve CPU efficiency even when total transfer time is unchanged.

Source references are pinned to b6cf44f7b8a1523409e0e998e478c996ac970f03. This request describes an optimization opportunity; it does not claim a measured end-to-end speedup.

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