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

Minor optimisations #454

Merged
merged 6 commits into from
May 20, 2024
Merged

Minor optimisations #454

merged 6 commits into from
May 20, 2024

Conversation

adam-fowler
Copy link
Member

Don't allocate ByteBuffer before we know its size.
Provide contentLength when generating responses so header field size is not recalculated, when contentLength is added
Use HTTPFields.contains instead of subscript which constructs contents of HTTPField

@adam-fowler adam-fowler requested a review from Joannis May 19, 2024 11:35
let string = try self.encode(value)
var buffer = context.allocator.buffer(capacity: string.utf8.count)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not create the buffer from the string using NIO's helpers?

Copy link
Member Author

Choose a reason for hiding this comment

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

No because that uses a temporary allocator and not the one that was attached to the Channel

let data = try self.encode(value)
var buffer = context.allocator.buffer(capacity: data.count)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use NIO's allocator helpers here

Copy link
Member Author

Choose a reason for hiding this comment

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

No because that uses a temporary allocator and not the one that was attached to the Channel

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair point. Will fix

Copy link
Contributor

@Joannis Joannis left a comment

Choose a reason for hiding this comment

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

I don't mind merging this as-is. But it seems sensible to me to merge the call to allocate and write into one.

adam-fowler and others added 2 commits May 20, 2024 07:16
Co-authored-by: Joannis Orlandos <joannis@orlandos.nl>
@adam-fowler adam-fowler merged commit 2c80d7b into main May 20, 2024
5 checks passed
@adam-fowler adam-fowler deleted the optimisation branch May 20, 2024 06:33
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