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

[improvement] use of factory method to avoid OpenSpan.Builder allocations #167

Merged
merged 1 commit into from
Jun 7, 2019
Merged

[improvement] use of factory method to avoid OpenSpan.Builder allocations #167

merged 1 commit into from
Jun 7, 2019

Conversation

wenhoujx
Copy link
Contributor

@wenhoujx wenhoujx commented Jun 6, 2019

  • keep builder() method for back-compat.

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 avoids Builder allocation.

- keep builder() method for back-compat
@wenhoujx wenhoujx requested a review from a team as a code owner June 6, 2019 20:19
@wenhoujx
Copy link
Contributor Author

wenhoujx commented Jun 6, 2019

image

@wenhoujx
Copy link
Contributor Author

wenhoujx commented Jun 6, 2019

@carterkozak @schlosna

Copy link
Contributor

@schlosna schlosna left a 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()));
Copy link
Contributor

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.

Copy link
Contributor Author

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.....) ;

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@schlosna schlosna mentioned this pull request Jun 7, 2019
/**
* 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) {
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 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!

@bulldozer-bot bulldozer-bot bot merged commit c1d5d74 into palantir:develop Jun 7, 2019
@wenhoujx wenhoujx deleted the whou/path1/avoidBuilderAllocation branch June 7, 2019 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants