perf: Use LinkedHashSet to deduplicate search domains - #17400
Conversation
b6c6c50 to
0ba96ff
Compare
|
@JunggiKim did you sign our icla yet ? https://netty.io/s/icla This change looks good... That said the impact is more or less meaningless in real-world as it is just used in the builder. |
|
@normanmaurer Regarding the PR, while the performance impact in a real-world environment might be minimal, the change itself carries very low risk. Therefore, I believe it would still be a nice improvement to merge. However, I completely respect your decision. If you feel this change isn't necessary, please feel free to close this PR (or let me know, and I can close it myself). Thanks again for your time and review! |
|
Hi @normanmaurer, I investigated the failed CI job. The only failed check is This PR changes only TestLens marks this exact test as flaky: 4 flaky outcomes in 1,418 recent runs Could a maintainer please rerun only the failed Thank you. |
Co-authored-by: Norman Maurer <norman_maurer@apple.com>
|
Thanks for applying the suggestions directly, @normanmaurer — using Set as the declared type is cleaner. Nothing further from my side the branch is up to date |
🚨 TestLens detected 2 failed tests 🚨Here is what you can do:
Test SummaryBuild PR / linux-x86_64-java11-boringssl-jdk8-tests build > Netty/Codec/HTTP2
Build PR / windows-x86_64-java11-boringssl > Netty/Handler
🏷️ Commit: 31e15b8 Test FailuresHttp2ConnectionRoundtripTest > createStreamAfterReceiveGoAwayShouldNotSendGoAway() (Netty/Codec/HTTP2 in Build PR / linux-x86_64-java11-boringssl-jdk8-tests build)
OpenSslConscryptSslEngineInteropTest > testSessionInvalidate(SSLEngineTestParam) > [4] OpenSslEngineTestParam{type=Direct, protocolCipherCombo=ProtocolCipherCombo{protocol='TLSv1.2', cipher='TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256'}, delegate=false, useTasks=false, useTickets=true} (Netty/Handler in Build PR / windows-x86_64-java11-boringssl)
Rerun ControlsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
|
Auto-port PR for 4.1: #17407 |
|
Auto-port PR for 5.0: #17408 |
…17407) Auto-port of #17400 to 4.1 Cherry-picked commit: 4021ead --- Motivation: `DnsNameResolverBuilder.searchDomains` keeps unique domains in an `ArrayList`. For every new domain, `List.contains` scans the values already collected. A large list of distinct domains therefore performs a growing number of comparisons. Modification: Use one `LinkedHashSet` while reading the supplied `Iterable`. It removes duplicates in expected constant time and preserves the first-seen order. Convert the set to the existing `String[]` field after the loop, so resolver lookup order and the stored representation stay unchanged. Add a regression test for order, duplicate removal, case sensitivity, `Aa` / `BB` hash collisions, and stopping at the first `null` value. Result: The duplicate-checking work changes from O(N^2) for N distinct domains to expected O(N). A local JMH collection-loop benchmark on JDK 21, with 2 forks, measured: | Distinct domains | ArrayList | LinkedHashSet | | ---: | ---: | ---: | | 64 | 3.196 us/op | 1.065 us/op | | 256 | 46.678 us/op | 4.584 us/op | | 1024 | 780.932 us/op | 26.025 us/op | | 4096 | 12196.313 us/op | 147.224 us/op | This is builder configuration work, not DNS request latency. Inputs containing only repeated values may be slower because the old list stays at one element. Verification: ```text ./mvnw -pl resolver-dns -am -Dtest=DnsNameResolverBuilderTest \ -Dsurefire.failIfNoSpecifiedTests=false test ``` The reactor build succeeded. `DnsNameResolverBuilderTest` ran 10 tests with zero failures, errors, or skipped tests. Co-authored-by: kjg <kimjg2477@gmail.com> Co-authored-by: Norman Maurer <norman_maurer@apple.com>
…17408) Auto-port of #17400 to 5.0 Cherry-picked commit: 4021ead --- Motivation: `DnsNameResolverBuilder.searchDomains` keeps unique domains in an `ArrayList`. For every new domain, `List.contains` scans the values already collected. A large list of distinct domains therefore performs a growing number of comparisons. Modification: Use one `LinkedHashSet` while reading the supplied `Iterable`. It removes duplicates in expected constant time and preserves the first-seen order. Convert the set to the existing `String[]` field after the loop, so resolver lookup order and the stored representation stay unchanged. Add a regression test for order, duplicate removal, case sensitivity, `Aa` / `BB` hash collisions, and stopping at the first `null` value. Result: The duplicate-checking work changes from O(N^2) for N distinct domains to expected O(N). A local JMH collection-loop benchmark on JDK 21, with 2 forks, measured: | Distinct domains | ArrayList | LinkedHashSet | | ---: | ---: | ---: | | 64 | 3.196 us/op | 1.065 us/op | | 256 | 46.678 us/op | 4.584 us/op | | 1024 | 780.932 us/op | 26.025 us/op | | 4096 | 12196.313 us/op | 147.224 us/op | This is builder configuration work, not DNS request latency. Inputs containing only repeated values may be slower because the old list stays at one element. Verification: ```text ./mvnw -pl resolver-dns -am -Dtest=DnsNameResolverBuilderTest \ -Dsurefire.failIfNoSpecifiedTests=false test ``` The reactor build succeeded. `DnsNameResolverBuilderTest` ran 10 tests with zero failures, errors, or skipped tests. Co-authored-by: kjg <kimjg2477@gmail.com> Co-authored-by: Norman Maurer <norman_maurer@apple.com>
Motivation:
DnsNameResolverBuilder.searchDomainskeeps unique domains in anArrayList.For every new domain,
List.containsscans the values already collected. A largelist of distinct domains therefore performs a growing number of comparisons.
Modification:
Use one
LinkedHashSetwhile reading the suppliedIterable. It removesduplicates in expected constant time and preserves the first-seen order. Convert
the set to the existing
String[]field after the loop, so resolver lookup orderand the stored representation stay unchanged.
Add a regression test for order, duplicate removal, case sensitivity,
Aa/BBhash collisions, and stopping at the first
nullvalue.Result:
The duplicate-checking work changes from O(N^2) for N distinct domains to expected
O(N). A local JMH collection-loop benchmark on JDK 21, with 2 forks, measured:
This is builder configuration work, not DNS request latency. Inputs containing
only repeated values may be slower because the old list stays at one element.
Verification:
The reactor build succeeded.
DnsNameResolverBuilderTestran 10 tests with zerofailures, errors, or skipped tests.