Skip to content

Commit

Permalink
Simplify Tracer.shouldObserve (#870)
Browse files Browse the repository at this point in the history
Simplify Tracer.shouldObserve to avoid JIT friction
  • Loading branch information
carterkozak authored Mar 9, 2022
1 parent 6cafc31 commit 18fbd90
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-870.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Simplify Tracer.shouldObserve to avoid JIT friction
links:
- https://github.com/palantir/tracing-java/pull/870
13 changes: 2 additions & 11 deletions tracing/src/main/java/com/palantir/tracing/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.palantir.logsafe.Safe;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.UnsafeArg;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import com.palantir.logsafe.exceptions.SafeIllegalStateException;
import com.palantir.logsafe.exceptions.SafeRuntimeException;
import com.palantir.logsafe.logger.SafeLogger;
Expand Down Expand Up @@ -86,16 +85,8 @@ private static Trace createTrace(
}

private static boolean shouldObserve(Observability observability) {
switch (observability) {
case SAMPLE:
return true;
case DO_NOT_SAMPLE:
return false;
case UNDECIDED:
return sampler.sample();
}

throw new SafeIllegalArgumentException("Unknown observability", SafeArg.of("observability", observability));
// Simplified implementation of 'switch(observability) {' for fast inlining (30 bytes)
return observability == Observability.SAMPLE || (observability == Observability.UNDECIDED && sampler.sample());
}

/**
Expand Down

0 comments on commit 18fbd90

Please sign in to comment.