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

7% of the overall runtime spent in SelectableEventLoop.debugDescription #754

Open
weissi opened this issue Jul 23, 2024 · 0 comments
Open
Labels
performance Issues relating to performance

Comments

@weissi
Copy link
Contributor

weissi commented Jul 23, 2024

Just noticed that when just running loads of sequential super basic HTTP requests against a fast server (NIOHTTP1Server), we spent about 7% of the overall runtime in HTTP1ClientChannelHandler.request.setter which spends most of its time in _print_unlocked<A, B>(_:_:) because it's pulling a debugDescription for EventLoop for the logger metadata :P (release mode compile of course)

Should be an easy fix.

requestLogger[metadataKey: "ahc-el"] = "\(self.eventLoop)"

Screenshot 2024-07-23 at 11 55 05 am

FWIW, the super basic perf test I used is this: weissi@bf7dbeb (this code isn't meant to be merged).

@weissi weissi added the performance Issues relating to performance label Jul 23, 2024
Lukasa added a commit that referenced this issue Sep 23, 2024
…Handler (#772)

### Motivation:

A performance test executing 100,000 sequential requests against a
simple
[`NIOHTTP1Server`](https://github.com/apple/swift-nio/blob/main/Sources/NIOHTTP1Server/README.md)
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)"`](https://github.com/swift-server/async-http-client/blob/6df8e1c17e68f0f93de2443b8c8cafca9ddcc89a/Sources/AsyncHTTPClient/ConnectionPool/HTTP1/HTTP1ClientChannelHandler.swift#L39C17-L39C75)
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.

---------

Co-authored-by: Cory Benfield <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Issues relating to performance
Projects
None yet
Development

No branches or pull requests

1 participant