Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance fixes based on hotspot analysis in load tests #11148

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Span span() {

protected void putContext(JaegerSpanContext spanContext) {
MDC.put(TRACE_ID, spanContext.getTraceId());
MDC.put(SPAN_ID, String.format("%16x", spanContext.getSpanId()));
MDC.put(SPAN_ID, Long.toHexString(spanContext.getSpanId()));
MDC.put(SAMPLED, Boolean.toString(spanContext.isSampled()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public boolean equals(Object obj) {
return false;
}
Key other = (Key) obj;
// Shortcut removes hotspot on contextual.equals
if (contextual == other.contextual) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, at the moment we don't implement equals()/hashCode() for generated bean classes so !contextual.equals(other.contextual) should be translated to !(contextual == other.contextual). In other words, this modification could save one java.lang.Object.equals(Object) invocation (which is very likely negligible although it removes the equals method from the hot path). Long.toHexString() saves probably a lot more because String.format() creates a formatter object, parses the string, etc.

Copy link
Member

Choose a reason for hiding this comment

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

@mkouba what's you're saying is we should drop the equals() call altogether?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope. I'd like to keep it. The fact that we don't implement it now does not mean we'll never need to implement it.

Copy link
Member

Choose a reason for hiding this comment

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

OK. But if it ended up being a hot spot for Paul, there's something weird going on.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's hard to say without the app and test sources. CC @bcluap

Copy link
Contributor

Choose a reason for hiding this comment

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

So, I just saw that the profiler used is the one from VisualVM, it inject some bytecode and can generates deoptimization.
That's why it can misleading you to such kind of hotspot.
When working on lowlevel optimizations (and avoiding a method call is very low level), you should use low level stuff like async-profiler, we have a page that expalain how to use it: https://github.com/quarkusio/quarkus/blob/master/TROUBLESHOOTING.md

So again, the hotspot for the equals method call is certainly a profiler artefact not a real hotspot.
And 1% difference between two load testing run is very slight so can go into the recording error range.
Such small performance enhancements should be validated via microbenchmarking using JMH ...

Copy link
Contributor

Choose a reason for hiding this comment

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

Such small performance enhancements should be validated via microbenchmarking using JMH ...

Yes, we talked about this in the comments below, e.g. #11148 (comment).

Copy link
Member

Choose a reason for hiding this comment

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

If you have many possible concrete types implementing Contextual, the dispatch to find the right equals implementation becomes a very expensive megamorphic call.
+1 for the shortcut

Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned above we removed the need for equals() from the hot path completely...

Copy link
Member

Choose a reason for hiding this comment

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

As mentioned above we removed the need for equals() from the hot path completely...

Sure that's even better. I just meant to suggest a possible explanation for the equals to be - in some contexts - really not that efficient. Removing the field is even better!

return true;
}
if (!contextual.equals(other.contextual)) {
return false;
}
Expand Down