swift-server / swift-server/swift-http-server
Offer ResponseSender.Writer RawSpan APIs
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 44
- Forks
- 13
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 8
Description
We should offer RawSpan APIs for the ResponseSender.Writer to avoid an extra copy when it takes the container and copies it to a ByteBuffer. If we have a RawSpan API we can bypass that allocation for every write. I verified this in Vapor 5 where currently we have to stage every chunk into a UniqueArray. I've tested this and it reduces the copy for every write, which can add up when streaming large responses. It reduces it down to a single copy in the pipeline. Will submit a PR with the new APIs.
We can write overloads to do a borrow instead of the copy:
public mutating func write(_ bytes: RawSpan) async throws(WriteFailure)
public consuming func finish(bytes: RawSpan, finalElement: consuming HTTPFields?) async throws(WriteFailure)
Note that we'd need an overload for finish as well which covers non-streaming cases.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at ResponseSender.Writer and trace how writes currently stage chunks in a UniqueArray before copying to a ByteBuffer. Compare the existing write and finish APIs, including the non-streaming finish path. Done means RawSpan overloads cover writing and finishing while reducing the pipeline to a single copy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- api, backend, performance
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100