Reduce time spent logging EventLoop description in HTTP1ClientChannelHandler #772
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 therequest
property inHTTP1ClientChannelHandler
(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 initializingHTTP1ClientChannelHandler
, and using that stored value inrequest
's setter, rather than computing the property each time.Modifications:
let eventLoopDescription: Logger.MetadataValue
inHTTP1ClientChannelHandler
that stores the description of theeventLoop
argument that is passed into the initializer."\(self.eventLoop)"
inrequest
's setter withself.eventLoopDescription
.Result:
HTTP1ClientChannelHandler.eventLoop
'sdescription
property is cached upon initialization rather than being computed each time in therequest
property's setter.