From f07115c2a68f24fd6febf1be177eeb129a947d52 Mon Sep 17 00:00:00 2001 From: feijermu Date: Mon, 9 Mar 2020 15:47:53 +0800 Subject: [PATCH] Add a log level check simply before logging. (#10093) Motivation: ThrowableUtil.stackTraceToString is an expensive method call. So I think a log level check before this logging statement is quite needed especially in a environment with the warning log disabled. Modification: Add log level check simply before logging. Result: Improve performance in a environment with the warning log disabled. --- .../java/io/netty/util/internal/PromiseNotificationUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/io/netty/util/internal/PromiseNotificationUtil.java b/common/src/main/java/io/netty/util/internal/PromiseNotificationUtil.java index 42872a8b8a..90a7c896eb 100644 --- a/common/src/main/java/io/netty/util/internal/PromiseNotificationUtil.java +++ b/common/src/main/java/io/netty/util/internal/PromiseNotificationUtil.java @@ -65,7 +65,7 @@ public final class PromiseNotificationUtil { Throwable err = p.cause(); if (err == null) { logger.warn("Failed to mark a promise as failure because it has succeeded already: {}", p, cause); - } else { + } else if (logger.isWarnEnabled()) { logger.warn( "Failed to mark a promise as failure because it has failed already: {}, unnotified cause: {}", p, ThrowableUtil.stackTraceToString(err), cause);