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

Reduce time spent logging EventLoop description in HTTP1ClientChannelHandler #772

Merged
merged 4 commits into from
Sep 23, 2024

Conversation

aryan-25
Copy link
Contributor

Motivation:

A performance test executing 100,000 sequential requests against a simple NIOHTTP1Server revealed that 7% of total run time is spent in the setter of the request property in HTTP1ClientChannelHandler (GitHub Issue #754).

The poor performance comes from processing the string interpolation "\(self.eventLoop)" which under the hood calls a computed property.

This problem can entirely be avoided by storing eventLoop.description when initializing HTTP1ClientChannelHandler, and using that stored value in request's setter, rather than computing the property each time.

Modifications:

  • Created a new property let eventLoopDescription: Logger.MetadataValue in HTTP1ClientChannelHandler that stores the description of the eventLoop argument that is passed into the initializer.
  • Replaced the string interpolation "\(self.eventLoop)" in request's setter with self.eventLoopDescription.

Result:

HTTP1ClientChannelHandler.eventLoop's description property is cached upon initialization rather than being computed each time in the request property's setter.

@Lukasa Lukasa enabled auto-merge (squash) September 23, 2024 11:28
@Lukasa Lukasa merged commit 38608db into swift-server:main Sep 23, 2024
6 of 7 checks passed
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.

2 participants