Don't use logVarargs method to improve performance

Calling the logVarargs method is expensive since it requires allocating
an object array. Instead have multiple logDebug methods that accept
different numbers of arguments. This is in line with Floggers best
practice of avoiding varargs entirely [1].

[1] https://google.github.io/flogger/anatomy

Change-Id: I7a66f63c77a7f4da71131823e7cef144b52dd58b
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2018-06-08 11:20:09 +02:00
parent bf734b9d77
commit 8954ede856
7 changed files with 93 additions and 14 deletions

View File

@@ -3096,8 +3096,30 @@ class ReceiveCommits {
return cmd.getRefName().equals(RefNames.REFS_CONFIG);
}
private void logDebug(String msg, Object... args) {
logger.atFine().logVarargs(receiveId + msg, args);
private void logDebug(String msg) {
logger.atFine().log(receiveId + msg);
}
private void logDebug(String msg, @Nullable Object arg) {
logger.atFine().log(receiveId + msg, arg);
}
private void logDebug(String msg, @Nullable Object arg1, @Nullable Object arg2) {
logger.atFine().log(receiveId + msg, arg1, arg2);
}
private void logDebug(
String msg, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3) {
logger.atFine().log(receiveId + msg, arg1, arg2, arg3);
}
private void logDebug(
String msg,
@Nullable Object arg1,
@Nullable Object arg2,
@Nullable Object arg3,
@Nullable Object arg4) {
logger.atFine().log(receiveId + msg, arg1, arg2, arg3, arg4);
}
private void logWarn(String msg, Throwable t) {

View File

@@ -103,7 +103,11 @@ public class GitModules {
return ret;
}
private void logDebug(String msg, Object... args) {
logger.atFine().logVarargs(submissionId + msg, args);
private void logDebug(String msg, @Nullable Object arg) {
logger.atFine().log(submissionId + msg, arg);
}
private void logDebug(String msg, @Nullable Object arg1, @Nullable Object arg2) {
logger.atFine().log(submissionId + msg, arg1, arg2);
}
}

View File

@@ -936,8 +936,12 @@ public class MergeOp implements AutoCloseable {
+ " failed";
}
private void logDebug(String msg, Object... args) {
logger.atFine().logVarargs(submissionId + msg, args);
private void logDebug(String msg) {
logger.atFine().log(submissionId + msg);
}
private void logDebug(String msg, @Nullable Object arg) {
logger.atFine().log(submissionId + msg, arg);
}
private void logWarn(String msg, Throwable t) {

View File

@@ -22,6 +22,7 @@ import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.SubmitRecord;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Branch;
@@ -600,8 +601,25 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
}
}
protected final void logDebug(String msg, Object... args) {
logger.atFine().logVarargs(this.args.submissionId + msg, args);
protected final void logDebug(String msg) {
logger.atFine().log(this.args.submissionId + msg);
}
protected final void logDebug(String msg, @Nullable Object arg) {
logger.atFine().log(this.args.submissionId + msg, arg);
}
protected final void logDebug(String msg, @Nullable Object arg1, @Nullable Object arg2) {
logger.atFine().log(this.args.submissionId + msg, arg1, arg2);
}
protected final void logDebug(
String msg,
@Nullable Object arg1,
@Nullable Object arg2,
@Nullable Object arg3,
@Nullable Object arg4) {
logger.atFine().log(this.args.submissionId + msg, arg1, arg2, arg3, arg4);
}
protected final void logWarn(String msg, Throwable t) {

View File

@@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.MultimapBuilder;
import com.google.common.collect.SetMultimap;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.SubscribeSection;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.reviewdb.client.Branch;
@@ -676,7 +677,15 @@ public class SubmoduleOp {
bu.addRepoOnlyOp(new GitlinkOp(branch));
}
private void logDebug(String msg, Object... args) {
logger.atFine().logVarargs(orm.getSubmissionId() + " " + msg, args);
private void logDebug(String msg) {
logger.atFine().log(orm.getSubmissionId() + " " + msg);
}
private void logDebug(String msg, @Nullable Object arg) {
logger.atFine().log(orm.getSubmissionId() + " " + msg, arg);
}
private void logDebug(String msg, @Nullable Object arg1, @Nullable Object arg2) {
logger.atFine().log(orm.getSubmissionId() + " " + msg, arg1, arg2);
}
}

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.server.submit;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.change.TestSubmitInput;
import com.google.gerrit.server.update.BatchUpdateOp;
@@ -49,7 +50,7 @@ class TestHelperOp implements BatchUpdateOp {
}
}
private void logDebug(String msg, Object... args) {
logger.atFine().logVarargs(submissionId + msg, args);
private void logDebug(String msg, @Nullable Object arg) {
logger.atFine().log(submissionId + msg, arg);
}
}

View File

@@ -385,17 +385,38 @@ public abstract class BatchUpdate implements AutoCloseable {
}
protected void logDebug(String msg, Throwable t) {
// Only log if there is a requestId assigned, since those are the
// expensive/complicated requests like MergeOp. Doing it every time would be
// noisy.
if (requestId != null) {
logger.atFine().withCause(t).log(requestId + "%s", msg);
}
}
protected void logDebug(String msg, Object... args) {
protected void logDebug(String msg) {
// Only log if there is a requestId assigned, since those are the
// expensive/complicated requests like MergeOp. Doing it every time would be
// noisy.
if (requestId != null) {
logger.atFine().logVarargs(requestId + msg, args);
logger.atFine().log(requestId + msg);
}
}
protected void logDebug(String msg, @Nullable Object arg) {
// Only log if there is a requestId assigned, since those are the
// expensive/complicated requests like MergeOp. Doing it every time would be
// noisy.
if (requestId != null) {
logger.atFine().log(requestId + msg, arg);
}
}
protected void logDebug(String msg, @Nullable Object arg1, @Nullable Object arg2) {
// Only log if there is a requestId assigned, since those are the
// expensive/complicated requests like MergeOp. Doing it every time would be
// noisy.
if (requestId != null) {
logger.atFine().log(requestId + msg, arg1, arg2);
}
}
}