Skip to content

Share request/response conclusion state to save allocation - #157

Open
aryan-25 wants to merge 4 commits into
swift-server:mainfrom
aryan-25:request-reader-state-refactor
Open

aryan-25 wants to merge 4 commits into
swift-server:mainfrom
aryan-25:request-reader-state-refactor

Conversation

@aryan-25

@aryan-25 aryan-25 commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

We currently allocate for a class in both the request reader and response writer. This class tracks whether the reader/writer have finished reading the request / writing the response. Both of these properties are read by the same caller. We can therefore save an allocation if we share this state across both the reader and writer.

Modifications

  • Introduced an ExchangeState type which replaces the state classes of the reader and response writer.
  • Introduced an ancillary type HTTP1ConnectionReuseCoordinator to encapsulate the iterator moving logic required for connection re-use.

Result

An allocation saved for each request.

@aryan-25 aryan-25 added the 🔨 semver/patch No public API change. label Oct 23, 2026

@FranzBusch FranzBusch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks okay for now. In the future we can completely get rid of this allocation by making the reader and writer ~Escapable and using a MutableRef to share the state into the reader/writer and read it out after the response handler is done

@aryan-25
aryan-25 marked this pull request as ready for review October 26, 2026 11:15
@aryan-25
aryan-25 requested a review from gjcairo as a code owner October 26, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants