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

opentelemetry: slightly improve OpentemetrySubscriber's performance by pre-determined the attribute length #1327

Merged
merged 4 commits into from
Jun 24, 2021

Conversation

Folyd
Copy link
Contributor

@Folyd Folyd commented Mar 26, 2021

The SpanBuilder uses Vec to store span's fields. However, the current solution
can be slightly improved by preparing the capacity of Vec in advance, this can reduce
a few memory reallocations.

Since the max number of tracing's span fields is 32, we can replace Vec with SmallVec to
further improve performance. Maybe, we should add a new feature
(such as smallvec?) to the opentelemetry crate. Well, this should be discussed in the opentelemetry repo.

@Folyd Folyd requested review from carllerche, hawkw, jtescher and a team as code owners March 26, 2021 14:54
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

Overall this looks great, I had a couple little suggestions.

Would be nice to get @jtescher's eyes on this as well.

tracing-core/src/span.rs Outdated Show resolved Hide resolved
tracing-opentelemetry/src/subscriber.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@jtescher jtescher left a comment

Choose a reason for hiding this comment

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

Agree with @hawkw's comments, other than that looks good to me

@jtescher jtescher added the crate/opentelemetry Related to the `tracing-opentelemetry` crate. label Apr 15, 2021
hawkw added a commit that referenced this pull request Apr 15, 2021
## Motivation

Exposing an accessor for the `FieldSet` on `Attributes` can motivate the
subscriber to achieve some performance improvement, such as
`OpenTelemetrySubscriber` #1327.

## Alternative

Make `ValueSet::field_set()` be `pub` instead of `pub(crate)`.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Apr 16, 2021
## Motivation

Exposing an accessor for the `FieldSet` on `Attributes` can motivate the
subscriber to achieve some performance improvement, such as
`OpenTelemetrySubscriber` #1327.

## Alternative

Make `ValueSet::field_set()` be `pub` instead of `pub(crate)`.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Apr 16, 2021
## Motivation

Exposing an accessor for the `FieldSet` on `Attributes` can motivate the
subscriber to achieve some performance improvement, such as
`OpenTelemetrySubscriber` #1327.

## Alternative

Make `ValueSet::field_set()` be `pub` instead of `pub(crate)`.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Apr 16, 2021
## Motivation

Exposing an accessor for the `FieldSet` on `Attributes` can motivate the
subscriber to achieve some performance improvement, such as
`OpenTelemetrySubscriber` #1327.

## Alternative

Make `ValueSet::field_set()` be `pub` instead of `pub(crate)`.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Apr 16, 2021
## Motivation

Exposing an accessor for the `FieldSet` on `Attributes` can motivate the
subscriber to achieve some performance improvement, such as
`OpenTelemetrySubscriber` #1327.

## Alternative

Make `ValueSet::field_set()` be `pub` instead of `pub(crate)`.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Apr 17, 2021
## Motivation

Exposing an accessor for the `FieldSet` on `Attributes` can motivate the
subscriber to achieve some performance improvement, such as
`OpenTelemetrySubscriber` #1327.

## Alternative

Make `ValueSet::field_set()` be `pub` instead of `pub(crate)`.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
@Folyd
Copy link
Contributor Author

Folyd commented May 19, 2021

I think we can merge this? 🚀

@hawkw hawkw merged commit 96eaaa0 into tokio-rs:master Jun 24, 2021
@Folyd Folyd deleted the improve-opentelemetry branch June 25, 2021 02:19
hawkw added a commit that referenced this pull request Jun 25, 2021
#1327)

The `SpanBuilder` uses `Vec` to store span's fields. However, the
current solution can be slightly improved by preparing the capacity of
`Vec` in advance, this can reduce a few memory reallocations. 

Since the max number of tracing's span fields is 32, we can replace
`Vec` with `SmallVec` to further improve performance. Maybe, we should
add a new feature (such as `smallvec`?) to the `opentelemetry` crate.
Well, this should be discussed in the `opentelemetry` repo.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Jun 26, 2021
#1327)

The `SpanBuilder` uses `Vec` to store span's fields. However, the
current solution can be slightly improved by preparing the capacity of
`Vec` in advance, this can reduce a few memory reallocations. 

Since the max number of tracing's span fields is 32, we can replace
`Vec` with `SmallVec` to further improve performance. Maybe, we should
add a new feature (such as `smallvec`?) to the `opentelemetry` crate.
Well, this should be discussed in the `opentelemetry` repo.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Jul 9, 2021
# 0.14.0 (July 9, 2021)

### Breaking Changes

- Upgrade to `v0.15.0` of `opentelemetry` ([#1441])
  For list of breaking changes in OpenTelemetry, see the
  [v0.14.0 changelog](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry/CHANGELOG.md#v0140).

### Added

- Spans now include Opentelemetry `code.namespace`, `code.filepath`, and
  `code.lineno` attributes ([#1411])

### Changed

- Improve performance by pre-allocating attribute `Vec`s ([#1327])

Thanks to @Drevoed, @lilymara-onesignal, and @Folyd for contributing
to this release!
hawkw added a commit that referenced this pull request Jul 9, 2021
# 0.14.0 (July 9, 2021)

### Breaking Changes

- Upgrade to `v0.15.0` of `opentelemetry` ([#1441])
  For list of breaking changes in OpenTelemetry, see the
  [v0.14.0 changelog](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry/CHANGELOG.md#v0140).

### Added

- Spans now include Opentelemetry `code.namespace`, `code.filepath`, and
  `code.lineno` attributes ([#1411])

### Changed

- Improve performance by pre-allocating attribute `Vec`s ([#1327])

Thanks to @Drevoed, @lilymara-onesignal, and @Folyd for contributing
to this release!

Closes #1462
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
tokio-rs#1327)

The `SpanBuilder` uses `Vec` to store span's fields. However, the
current solution can be slightly improved by preparing the capacity of
`Vec` in advance, this can reduce a few memory reallocations. 

Since the max number of tracing's span fields is 32, we can replace
`Vec` with `SmallVec` to further improve performance. Maybe, we should
add a new feature (such as `smallvec`?) to the `opentelemetry` crate.
Well, this should be discussed in the `opentelemetry` repo.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
# 0.14.0 (July 9, 2021)

### Breaking Changes

- Upgrade to `v0.15.0` of `opentelemetry` ([tokio-rs#1441])
  For list of breaking changes in OpenTelemetry, see the
  [v0.14.0 changelog](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry/CHANGELOG.md#v0140).

### Added

- Spans now include Opentelemetry `code.namespace`, `code.filepath`, and
  `code.lineno` attributes ([tokio-rs#1411])

### Changed

- Improve performance by pre-allocating attribute `Vec`s ([tokio-rs#1327])

Thanks to @Drevoed, @lilymara-onesignal, and @Folyd for contributing
to this release!

Closes tokio-rs#1462
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/opentelemetry Related to the `tracing-opentelemetry` crate.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants