Skip to content

Conversation

dqminh
Copy link

@dqminh dqminh commented Sep 1, 2025

In async heavy code, Box::pin contributes a large percentage of allocation time. We can switch to pin_project to remove Box::pin usage here.

This allows user to skip the boxing step and save a memory allocation.
This is configure with generic=true in attribute. For example

 #[span_fn("async_trait_span", generic = true)]

@dqminh dqminh force-pushed the telemetry-context-pin branch 2 times, most recently from 48f49c6 to 73ccf73 Compare September 4, 2025 11:54
@@ -230,6 +230,7 @@ log = { workspace = true, optional = true }
parking_lot_core = { workspace = true, optional = true }
regex = { workspace = true, optional = true }
thiserror = { workspace = true, optional = true }
pin-project = "1.1.10"
Copy link
Collaborator

@TheJokr TheJokr Sep 4, 2025

Choose a reason for hiding this comment

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

versions should go into the root Cargo.toml, this should only specify workspace = true. Also, for such simple cases pin-project-lite is preferable as it reduces compile times. (The latter is a macro_rules! while pin-project is a proc-macro.)

@@ -23,6 +24,24 @@ feature_use!(cfg(feature = "tracing"), {
#[cfg(feature = "testing")]
use super::testing::TestTelemetryContext;

#[pin_project]
pub struct WithTelemetryContextGeneric<T> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add a doc comment similar to WithTelemetryContextLocal

This allows user to skip the boxing step and save a memory allocation.
This is configure with `generic=true` in attribute. For example

```
 #[span_fn("async_trait_span", generic = true)]
```

Also add a feature `generic-telemetry-wrapper` so user can enable this
behavior by default.
@dqminh dqminh force-pushed the telemetry-context-pin branch from 73ccf73 to 998ce3c Compare September 10, 2025 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants