Skip to content

LineSequence.AsyncIterator should use a slice type for its underlyingBuffer to avoid unnecessary copies #165

@jlukas

Description

@jlukas

Describe the bug
When reading the output of a subprocess by lines, the underlying buffer returns a single character at a time from the front of its buffer. This requires copying the buffer each time. Instead, a slice type could be used to avoid this copying.

To Reproduce
My call is something like:

Subprocess.run() { execution, stdin, stdout, stderr in
    
    for try await line in stdout.lines() {
        
    }
}

Applying this diff reduces the time taken by subprocess from ~2 seconds to ~1 second (for calls with lots of output).

Environment (please complete the following information):

  • macOS 15
  • swift from various betas of Xcode 26, including: swift-driver version: 1.127.14.1 Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions