Skip to content

Commit cec67cf

Browse files
plokhotnyukslandelle
authored andcommitted
Reduce GC overhead by call address.toString() in case of timeout only (AsyncHttpClient#1401)
1 parent 6aaed08 commit cec67cf

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

client/src/main/java/org/asynchttpclient/netty/timeout/TimeoutsHolder.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class TimeoutsHolder {
3838
private volatile NettyResponseFuture<?> nettyResponseFuture;
3939
public final Timeout requestTimeout;
4040
public volatile Timeout readTimeout;
41-
private volatile String remoteAddress = "not-connected";
41+
private volatile InetSocketAddress remoteAddress;
4242

4343
public TimeoutsHolder(Timer nettyTimer, NettyResponseFuture<?> nettyResponseFuture, NettyRequestSender requestSender, AsyncHttpClientConfig config) {
4444
this.nettyTimer = nettyTimer;
@@ -61,7 +61,7 @@ public TimeoutsHolder(Timer nettyTimer, NettyResponseFuture<?> nettyResponseFutu
6161
}
6262

6363
public void initRemoteAddress(InetSocketAddress address) {
64-
remoteAddress = address.toString();
64+
remoteAddress = address;
6565
}
6666

6767
public void startReadTimeout() {
@@ -77,8 +77,7 @@ void startReadTimeout(ReadTimeoutTimerTask task) {
7777
// first call triggered from outside (else is read timeout is re-scheduling itself)
7878
task = new ReadTimeoutTimerTask(nettyResponseFuture, requestSender, this, readTimeoutValue);
7979
}
80-
Timeout readTimeout = newTimeout(task, readTimeoutValue);
81-
this.readTimeout = readTimeout;
80+
this.readTimeout = newTimeout(task, readTimeoutValue);
8281

8382
} else if (task != null) {
8483
// read timeout couldn't re-scheduling itself, clean up
@@ -104,6 +103,6 @@ private Timeout newTimeout(TimerTask task, long delay) {
104103
}
105104

106105
String remoteAddress() {
107-
return remoteAddress;
106+
return remoteAddress == null ? "not-connected" : remoteAddress.toString();
108107
}
109108
}

0 commit comments

Comments
 (0)