You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2022/10/02 14:42:00 UTC

[jira] [Commented] (HTTPCORE-713) Optimize InetAddressUtils#isIPv6*Address checks

    [ https://issues.apache.org/jira/browse/HTTPCORE-713?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17612124#comment-17612124 ] 

ASF subversion and git services commented on HTTPCORE-713:
----------------------------------------------------------

Commit c6dfb03a1c74cda8a1905f006efc640b680db886 in httpcomponents-core's branch refs/heads/github_ci_on_win from David Schlosnagle
[ https://gitbox.apache.org/repos/asf?p=httpcomponents-core.git;h=c6dfb03a1 ]

HTTPCORE-713: Optimize InetAddressUtils#isIPv6*Address

Check input colon count before performing IPv6 regex validation


> Optimize InetAddressUtils#isIPv6*Address checks
> -----------------------------------------------
>
>                 Key: HTTPCORE-713
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-713
>             Project: HttpComponents HttpCore
>          Issue Type: Improvement
>          Components: HttpCore
>            Reporter: David Schlosnagle
>            Priority: Major
>             Fix For: 5.1.4, 5.2-beta2
>
>         Attachments: 166573589-2c814d53-9639-4b14-82d0-9238f285be0b.png
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> See https://github.com/apache/httpcomponents-core/pull/347
> Check input colon count before performing IPv6 regex validation.
> {{org.apache.hc.core5.net.InetAddressUtils.isIPv6Address}} is used when constructing the {{host}} header for requests, and currently allocates a regex matcher when checking if the provided address is an IPv6 address. This is generates excess garbage and CPU cycles, especially in environments with mostly IPv4 addresses. By checking the colon count first, we see a 50x improvement checking {{InetAddressUtils.isIPv6Address}} for an IPv4 address.
> The specific call backtrace seen looks like:
> {code:java}
> void java.util.regex.Matcher.<init>(Pattern, CharSequence)
>    Matcher java.util.regex.Pattern.matcher(CharSequence)
>    boolean org.apache.hc.core5.net.InetAddressUtils.isIPv6HexCompressedAddress(String)
>       boolean org.apache.hc.core5.net.InetAddressUtils.isIPv6Address(String)
>       void org.apache.hc.core5.net.Host.format(StringBuilder, NamedEndpoint)
>       void org.apache.hc.core5.net.URIAuthority.format(StringBuilder, URIAuthority)
>          String org.apache.hc.core5.net.URIAuthority.format(URIAuthority)
>          String org.apache.hc.core5.net.URIAuthority.toString()
>          String java.util.Objects.toString(Object, String)
>          void org.apache.hc.core5.http.message.BasicHeader.<init>(String, Object, boolean)
>          void org.apache.hc.core5.http.message.BasicHeader.<init>(String, Object)
>          void org.apache.hc.core5.http.message.BasicHttpRequest.addHeader(String, Object)
>          void org.apache.hc.core5.http.protocol.RequestTargetHost.process(HttpRequest, EntityDetails, HttpContext)
>          void org.apache.hc.core5.http.protocol.DefaultHttpProcessor.process(HttpRequest, EntityDetails, HttpContext)
>          ClassicHttpResponse org.apache.hc.client5.http.impl.classic.ProtocolExec.execute(ClassicHttpRequest, ExecChain$Scope, ExecChain)
>          ClassicHttpResponse org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ClassicHttpRequest, ExecChain$Scope)
>          ClassicHttpResponse org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ClassicHttpRequest, ExecChain$Scope)
>          ClassicHttpResponse org.apache.hc.client5.http.impl.classic.RedirectExec.execute(ClassicHttpRequest, ExecChain$Scope, ExecChain)
>          ClassicHttpResponse org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ClassicHttpRequest, ExecChain$Scope)
>          CloseableHttpResponse org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(HttpHost, ClassicHttpRequest, HttpContext)
>          CloseableHttpResponse org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(ClassicHttpRequest, HttpContext)
>          CloseableHttpResponse org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(ClassicHttpRequest)
> {code}
> From JFR profile: 
> !166573589-2c814d53-9639-4b14-82d0-9238f285be0b.png! 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org