Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-849.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Trace threadlocal entry is never removed, only nulled
links:
- https://github.com/palantir/tracing-java/pull/849
2 changes: 1 addition & 1 deletion tracing-benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tasks.jmhCompileGeneratedClasses {
}

dependencies {
annotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess'
jmhAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess'
compileOnly 'org.openjdk.jmh:jmh-generator-annprocess'
api 'org.immutables:value::annotations'
api 'org.openjdk.jmh:jmh-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS)
@Fork(1)
@Fork(value = 1, jvmArgsAppend = "-Dlog4j2.garbagefreeThreadContextMap=true")
@Threads(4)
@SuppressWarnings({"checkstyle:hideutilityclassconstructor", "checkstyle:VisibilityModifier"})
public class TracingBenchmark {
Expand Down Expand Up @@ -88,6 +88,12 @@ public static void nestedSpans() {
nestedSpans.run();
}

@Benchmark
public static void traceWithSingleSpan() {
Tracer.fastStartSpan("benchmark");
Tracer.fastCompleteSpan();
}

private static Runnable createNestedSpan(int depth) {
if (depth <= 0) {
return Runnables.doNothing();
Expand Down
2 changes: 1 addition & 1 deletion tracing/src/main/java/com/palantir/tracing/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ private static Trace getOrCreateCurrentTrace() {
@VisibleForTesting
static void clearCurrentTrace() {
logClearingTrace();
currentTrace.remove();
currentTrace.set(null);
MDC.remove(Tracers.TRACE_ID_KEY);
MDC.remove(Tracers.TRACE_SAMPLED_KEY);
MDC.remove(Tracers.REQUEST_ID_KEY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copying comment from #850

I didn't touch these as I didn't see these pop in profiles, and log4j2 uses org.apache.logging.log4j.spi.GarbageFreeSortedArrayThreadContextMap & org.apache.logging.log4j.util.SortedArrayStringMap where the MDC.remove & MDC.put don't directly free/allocate

Expand Down