-
Notifications
You must be signed in to change notification settings - Fork 19
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
[improvement] use of factory method to avoid OpenSpan.Builder allocations #167
[improvement] use of factory method to avoid OpenSpan.Builder allocations #167
Conversation
- keep builder() method for back-compat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM, think someone else will need to +1
Created #168 to remove some other allocations from hot paths when we're not observing that popped in similar profiles, especially for wrapped executors & high frequency endpoints at low sample rates.
// Avoid lambda allocation in hot paths | ||
if (prevState.isPresent()) { | ||
spanBuilder.parentSpanId(prevState.get().getSpanId()); | ||
span = OpenSpan.of(operation, Tracers.randomId(), type, Optional.of(prevState.get().getSpanId())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this is existing and we're stuck with this API, but the Optional
allocations on hot paths make me sad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
me sad too, do you think it's a good idea to create three methods to avoid the Optional
wrapping?
static OpenSpan.of( .......other params...... Optional<String> parentSpanId) ;
static OpenSpan.of( .......other params......String parentSpanId) ;
static OpenSpan.of( .......other params.....) ;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think its worth it as they'll still get created
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
/** | ||
* Use this factory method to avoid allocate {@link Builder} in hot path. | ||
*/ | ||
public static OpenSpan of(String operation, String spanId, SpanType type, Optional<String> parentSpanId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit of a shame that we have to make this public in order to access it within this library, as I really hope that no users will ever actually touch this class!
Before this PR
flight recording of my java application shows
OpenSpan$Builder
has 3200 TLAB allocations amounts to 167.99 MB total.After this PR
The static factory method
of
avoidsBuilder
allocation.