You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by do...@apache.org on 2024/04/26 20:25:25 UTC

(spark) branch master updated: [SPARK-48011][CORE] Store LogKey name as a value to avoid generating new string instances

This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 2b2a33cc35a8 [SPARK-48011][CORE] Store LogKey name as a value to avoid generating new string instances
2b2a33cc35a8 is described below

commit 2b2a33cc35a880fafc569c707674313a56c15811
Author: Gengliang Wang <ge...@apache.org>
AuthorDate: Fri Apr 26 13:25:15 2024 -0700

    [SPARK-48011][CORE] Store LogKey name as a value to avoid generating new string instances
    
    ### What changes were proposed in this pull request?
    
    Store LogKey name as a value to avoid generating new string instances
    ### Why are the changes needed?
    
    To save memory usage on getting the names of `LogKey`s.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    Existing tests
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No
    
    Closes #46249 from gengliangwang/addKeyName.
    
    Authored-by: Gengliang Wang <ge...@apache.org>
    Signed-off-by: Dongjoon Hyun <dh...@apple.com>
---
 common/utils/src/main/scala/org/apache/spark/internal/LogKey.scala  | 6 +++++-
 common/utils/src/main/scala/org/apache/spark/internal/Logging.scala | 4 +---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/common/utils/src/main/scala/org/apache/spark/internal/LogKey.scala b/common/utils/src/main/scala/org/apache/spark/internal/LogKey.scala
index 04990ddc4c9d..2ca80a496ccb 100644
--- a/common/utils/src/main/scala/org/apache/spark/internal/LogKey.scala
+++ b/common/utils/src/main/scala/org/apache/spark/internal/LogKey.scala
@@ -16,10 +16,14 @@
  */
 package org.apache.spark.internal
 
+import java.util.Locale
+
 /**
  * All structured logging `keys` used in `MDC` must be extends `LogKey`
  */
-trait LogKey
+trait LogKey {
+  val name: String = this.toString.toLowerCase(Locale.ROOT)
+}
 
 /**
  * Various keys used for mapped diagnostic contexts(MDC) in logging.
diff --git a/common/utils/src/main/scala/org/apache/spark/internal/Logging.scala b/common/utils/src/main/scala/org/apache/spark/internal/Logging.scala
index 085b22bee5f3..24a60f88c24a 100644
--- a/common/utils/src/main/scala/org/apache/spark/internal/Logging.scala
+++ b/common/utils/src/main/scala/org/apache/spark/internal/Logging.scala
@@ -17,8 +17,6 @@
 
 package org.apache.spark.internal
 
-import java.util.Locale
-
 import scala.jdk.CollectionConverters._
 
 import org.apache.logging.log4j.{CloseableThreadContext, Level, LogManager}
@@ -110,7 +108,7 @@ trait Logging {
         val value = if (mdc.value != null) mdc.value.toString else null
         sb.append(value)
         if (Logging.isStructuredLoggingEnabled) {
-          context.put(mdc.key.toString.toLowerCase(Locale.ROOT), value)
+          context.put(mdc.key.name, value)
         }
 
         if (processedParts.hasNext) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org