Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent unnecessary Copy-on-Write behaviour in HTTPFields #458

Closed
wants to merge 1 commit into from

Conversation

Joannis
Copy link
Contributor

@Joannis Joannis commented May 19, 2024

No description provided.

@Joannis Joannis requested a review from adam-fowler May 19, 2024 21:17
set { self.head.headerFields = newValue }
}
public var status: HTTPResponse.Status
public var headers: HTTPFields
Copy link
Contributor Author

Choose a reason for hiding this comment

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

First of all, modifying response.headers was leading to a CoW. This is because headers was a getter/setter, thus copied the value from head. I've reversed this relationship

self.body = body
if let contentLength = body.contentLength, headers[.contentLength] == nil {
self.head.headerFields[.contentLength] = String(describing: contentLength)
if let contentLength = body.contentLength, self.headers[.contentLength] == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

self. was missing, leading to the original headers still being references. This lead to there being two active copies, which would cause a CoW

adam-fowler added a commit that referenced this pull request May 20, 2024
Co-authored-by: Joannis Orlandos <joannis@orlandos.nl>
adam-fowler added a commit that referenced this pull request May 20, 2024
* Don't create ByteBuffer before we know its length

* Minor JSON change for performance test

* Add content-length to response generator body init

* Use HTTPFields.contains

Doesn't construct http field contents

* Use NIO helpers

* Combined with PR #458

Co-authored-by: Joannis Orlandos <joannis@orlandos.nl>

---------

Co-authored-by: Joannis Orlandos <joannis@orlandos.nl>
@adam-fowler
Copy link
Member

These changes were merged with #454 so this can be closed

@Joannis Joannis closed this May 20, 2024
@Joannis Joannis deleted the jo/prevent-httpfiels-cow branch May 20, 2024 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants