perf: Let HostnameCache worker thread idle out (JAVA-653) - #5817
Merged
Conversation
📲 Install BuildsAndroid
|
This was referenced Jul 22, 2026
runningcode
force-pushed
the
no/perf/hostname-cache-idle-thread
branch
from
July 22, 2026 15:53
b0b4168 to
b03da86
Compare
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| d15471f | 369.38 ms | 459.08 ms | 89.70 ms |
| bbc35bb | 324.88 ms | 425.73 ms | 100.85 ms |
| b193867 | 319.59 ms | 403.09 ms | 83.50 ms |
| 62b579c | 299.75 ms | 364.84 ms | 65.09 ms |
| 382d6c1 | 306.85 ms | 368.70 ms | 61.85 ms |
| 48277cd | 320.38 ms | 379.90 ms | 59.52 ms |
| 5b1a06b | 315.40 ms | 353.33 ms | 37.94 ms |
| ee747ae | 415.92 ms | 470.15 ms | 54.23 ms |
| 37ec571 | 366.04 ms | 424.28 ms | 58.23 ms |
| 462dea2 | 277.68 ms | 359.83 ms | 82.15 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| bbc35bb | 1.58 MiB | 2.12 MiB | 553.01 KiB |
| b193867 | 1.58 MiB | 2.19 MiB | 620.00 KiB |
| 62b579c | 0 B | 0 B | 0 B |
| 382d6c1 | 1.58 MiB | 2.29 MiB | 719.85 KiB |
| 48277cd | 0 B | 0 B | 0 B |
| 5b1a06b | 0 B | 0 B | 0 B |
| ee747ae | 1.58 MiB | 2.10 MiB | 530.95 KiB |
| 37ec571 | 0 B | 0 B | 0 B |
| 462dea2 | 0 B | 0 B | 0 B |
HostnameCache used Executors.newSingleThreadExecutor, whose worker thread stays alive for the life of the process even though the cache refreshes at most once every 5 hours. Use a ThreadPoolExecutor with a keep-alive and allowCoreThreadTimeOut(true) so the thread terminates when idle and is recreated on the next refresh. Keeping a dedicated executor (rather than sharing one) preserves the blocking future.get(1s) timeout behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
runningcode
force-pushed
the
no/perf/hostname-cache-idle-thread
branch
from
August 4, 2026 14:49
b03da86 to
8b8d967
Compare
runningcode
marked this pull request as ready for review
August 4, 2026 15:01
runningcode
requested review from
0xadam-brown,
adinauer,
markushi and
romtsn
as code owners
August 4, 2026 15:01
0xadam-brown
approved these changes
Aug 5, 2026
0xadam-brown
left a comment
Member
There was a problem hiding this comment.
Nice! One comment, no blockers 👍
This was referenced Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📜 Description
HostnameCache's executor stays around for the entire process lifetime (that's howThreadPoolExecutorswork by default) even though the cache only refreshes once every 5 hours. It now uses aThreadPoolExecutor(core = max = 1) with a 30s keep-alive andallowCoreThreadTimeOut(true), so the worker thread self-terminates when idle and is recreated on the next refresh.Alternatively, we can also use an existing executor for this but this is the smallest change here. Let me know if you think we should go that route.
💡 Motivation and Context
Part of reducing the number of threads created by the SDK: JAVA-653.
💚 How did you test it?
There are some new unit tests, but otherwise relying on ART/JVM to do their thing correctly.
📝 Checklist
sendDefaultPIIis enabled.