Permalink
Browse files

perf: guard logging statements (#1112)

Guard certain logging statements with `isLoggable` to prevent `Object[]` allocation for the argument vararg.
  • Loading branch information...
jesperpedersen authored and vlsi committed Jun 30, 2018
1 parent ba360f7 commit 7a0b7d65582a21376fc114eb197b5bae1fe1ea00
@@ -142,8 +142,10 @@ public QueryExecutor openConnectionImpl(HostSpec[] hostSpecs, String user, Strin
// GlobalHostStatusTracker
HostStatus knownStatus = knownStates.get(hostSpec);
if (knownStatus != null && !candidateHost.targetServerType.allowConnectingTo(knownStatus)) {
LOGGER.log(Level.FINER, "Known status of host {0} is {1}, and required status was {2}. Will try next host",
new Object[]{hostSpec, knownStatus, candidateHost.targetServerType});
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.log(Level.FINER, "Known status of host {0} is {1}, and required status was {2}. Will try next host",
new Object[]{hostSpec, knownStatus, candidateHost.targetServerType});
}
continue;
}

@@ -195,8 +197,10 @@ public QueryExecutor openConnectionImpl(HostSpec[] hostSpecs, String user, Strin
}
}

LOGGER.log(Level.FINE, "Receive Buffer Size is {0}", newStream.getSocket().getReceiveBufferSize());
LOGGER.log(Level.FINE, "Send Buffer Size is {0}", newStream.getSocket().getSendBufferSize());
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Receive Buffer Size is {0}", newStream.getSocket().getReceiveBufferSize());
LOGGER.log(Level.FINE, "Send Buffer Size is {0}", newStream.getSocket().getSendBufferSize());
}

List<String[]> paramList = getParametersForStartup(user, database, info);
sendStartupPacket(newStream, paramList);
@@ -2387,7 +2387,9 @@ public void handleCommandStatus(String status, int updateCount, long insertOID)
int size = pgStream.receiveInteger2();
Field[] fields = new Field[size];

LOGGER.log(Level.FINEST, " <=BE RowDescription({0})", size);
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " <=BE RowDescription({0})", size);
}

for (int i = 0; i < fields.length; i++) {
String columnLabel = pgStream.receiveString();
@@ -2510,7 +2512,9 @@ private void receiveRFQ() throws IOException {
}

char tStatus = (char) pgStream.receiveChar();
LOGGER.log(Level.FINEST, " <=BE ReadyForQuery({0})", tStatus);
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " <=BE ReadyForQuery({0})", tStatus);
}

// Update connection state.
switch (tStatus) {
@@ -2580,7 +2584,9 @@ public void readStartupMessages() throws IOException, SQLException {
break;

default:
LOGGER.log(Level.FINEST, " invalid message type={0}", (char) beresp);
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " invalid message type={0}", (char) beresp);
}
throw new PSQLException(GT.tr("Protocol error. Session setup failed."),
PSQLState.PROTOCOL_VIOLATION);
}
@@ -82,7 +82,9 @@ public void processServerMechanismsAndInit() throws IOException, PSQLException {
PSQLState.CONNECTION_REJECTED
);
}
LOGGER.log(Level.FINEST, " Using SCRAM mechanism {0}", scramClient.getScramMechanism().getName());
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " Using SCRAM mechanism {0}", scramClient.getScramMechanism().getName());
}

scramSession =
scramClient.scramSession("*"); // Real username is ignored by server, uses startup one
@@ -119,10 +121,12 @@ public void processServerFirstMessage(int length) throws IOException, PSQLExcept
e
);
}
LOGGER.log(Level.FINEST,
" <=BE AuthenticationSASLContinue(salt={0}, iterations={1})",
new Object[] { serverFirstProcessor.getSalt(), serverFirstProcessor.getIteration() }
);
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST,
" <=BE AuthenticationSASLContinue(salt={0}, iterations={1})",
new Object[] { serverFirstProcessor.getSalt(), serverFirstProcessor.getIteration() }
);
}

clientFinalProcessor = serverFirstProcessor.clientFinalProcessor(password);

0 comments on commit 7a0b7d6

Please sign in to comment.