-
Notifications
You must be signed in to change notification settings - Fork 20
Improve performance of getOperationName #230
Conversation
See the PR on the (dead) original repo: opentracing-contrib/java-interceptors#16 |
4e09744
to
4f909cb
Compare
I generally like this, but immediately thought: are the duplicate pieces of code in your new implementation any bad? I added this method to your benchmark: @Benchmark
public String ladicek() {
String className = method.getDeclaringClass().getName();
String methodName = method.getName();
int capacity = className.length() + methodName.length() + 1;
return new StringBuilder(capacity).append(className).append('.').append(methodName).toString();
} and ran it using OpenJDK 1.8.0_312 on my desktop machine (which was completely idle, I wasn't even looged into a GUI session). These are the results:
Looks like the duplicate pieces are any bad and simplifying the code per above should lead to even bigger gains :-) |
@Ladicek this looks interesting ! I can incorporate your change in my PR and run it again on Java 11 as it may behave differently than 8. I forgot that even if the method starts with |
I'm running the benchmark on JDK 11 now, but it takes a while :-) |
Ah and |
|
Here are the result on JDK 11, the new impl is in
|
Here are my results on OpenJDK 11.0.14.1:
I can't really explain the difference :-) |
4f909cb
to
edefc91
Compare
Well, we'll need to ge deeper using profiler, gc stats, asm ... Or we can just decide to go with it ;) I updated my patch to call the methods only once. |
Fun fact, by updating my benchmark method from
To
Which should translate to the same bytecode I have different results which are more aligned with what you observe. I'll dig a little more tomorrow. |
I relaunch the test yesterday and ... they now perform the same ... Anyway, the current code may performe 10x better, can we proceed with it @Ladicek ? |
LGTM, but I'll leave the decision to @radcortez :-) |
This is a copy of my PR on the (dead) original java interceptor lib.
I recently performance load test on an application using the java interceptor to send traces to Jaeger.
Inside a performance profile, I saw a high cost (3% total CPU cost, but more than 60% of span creation+start+finish time) for the
getOperationMethod
due to the usage of a StringFormatter.I did some small experiment with JHM, and using a StringBuilder with an initial capacity seems a better option (10x quicker). As creating span occurs in the hot path of an application, I think it's a good thing to remove this hotspot.
I try several approach, this seems to be the better. We can go with simple string concatenation if the code seems too complex, as since Java 9 (and the string concatenation improvement) it is as performant as using a StringBuilder.
Here is my JMH benchmark
And the result on my laptop (Linux - Java 11 - 6 cores)