Avoid spawning thread for trivial getnameinfo calls #14277
Merged
+12
−0
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.
When calling
getnameinfo
we spawn a thread because it may do a slow, blocking reverse-DNS lookup. Spawning a thread is relatively fast (~20µs on my Linux machine) but still an order of magnitude slower than whengetnameinfo
is simply translating to a numeric IP or port, which, at least in my tests on Linux, doesn't even make asyscall
.This commit adds a fast path for when reverse DNS isn't required: either host isn't being fetched or
NI_NUMERICHOST
is set AND either the service name isn't required orNI_NUMERICSERV
is set. The service name should only need to read/etc/services
, which should be fast-ish, but is still I/O so I kept the existing behaviour (it could be on a network fs I guess).I tested with:
Before: 12.935s
After: 0.338s