From 8097a516da077a655a22100622e2466d584e93be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Mon, 2 May 2022 17:57:28 +0200 Subject: [PATCH] Improve performance of getOperationName (#230) --- .../contrib/interceptor/OpenTracingInterceptor.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/contrib/src/main/java/io/smallrye/opentracing/contrib/interceptor/OpenTracingInterceptor.java b/contrib/src/main/java/io/smallrye/opentracing/contrib/interceptor/OpenTracingInterceptor.java index 4e65e5a..d2620cf 100644 --- a/contrib/src/main/java/io/smallrye/opentracing/contrib/interceptor/OpenTracingInterceptor.java +++ b/contrib/src/main/java/io/smallrye/opentracing/contrib/interceptor/OpenTracingInterceptor.java @@ -159,7 +159,14 @@ private String getOperationName(Method method) { } else if (classTraced != null && classTraced.operationName().length() > 0) { return classTraced.operationName(); } - return String.format("%s.%s", method.getDeclaringClass().getName(), method.getName()); + + // use a StringBuilder with predefined capacity to compute the operation name for performance reason + String className = method.getDeclaringClass().getName(); + String methodName = method.getName(); + int capacity = className.length() + methodName.length() + 1; + StringBuilder builder = new StringBuilder(capacity); + builder.append(className).append('.').append(methodName); + return builder.toString(); } private void logException(Span span, Exception e) {