Uh oh!
There was an error while loading. Please reload this page.
[improvement] use of factory method to avoid OpenSpan.Builder allocations - #167
[improvement] use of factory method to avoid OpenSpan.Builder allocations#167bulldozer-bot[bot] merged 1 commit into
Conversation
- keep builder() method for back-compat
wenhoujx
commented
Jun 6, 2019
wenhoujx
commented
Jun 6, 2019
schlosna
left a comment
There was a problem hiding this comment.
👍 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.
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.
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.
I don't think its worth it as they'll still get created
| /** | ||
| * 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.
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$Builderhas 3200 TLAB allocations amounts to 167.99 MB total.After this PR
The static factory method
ofavoidsBuilderallocation.