Skip to content

Commit cf5c2bd

Browse files
subscriber: remove clone_span on enter (#3289)
## Motivation Continuous profiling on a production workload shows that `Span::enter` is a significant percent of the samples. This is currently using `tracing-subscriber = "0.3.19"`. Concrete numbers: - 7.7% of samples were found within the stacktrace of a `Span::enter`. - Of those samples, 22.8% were inside `clone_span`. - Collectively, that's 1.8% of total CPU time spent in `clone_span` as a result of `Span::enter`. ## Solution Remove `clone_span` from `enter`, remove `try_close` from `exit`. This was originally included to protect against misuse of the `tracing-core` API. However, there has not been so much use of this low level API as was originally anticipated, and it is not worth the performance hit.
1 parent c287c84 commit cf5c2bd

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

tracing-subscriber/src/registry/sharded.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,15 @@ impl Subscriber for Registry {
288288
fn event(&self, _: &Event<'_>) {}
289289

290290
fn enter(&self, id: &span::Id) {
291-
if self
292-
.current_spans
291+
self.current_spans
293292
.get_or_default()
294293
.borrow_mut()
295-
.push(id.clone())
296-
{
297-
self.clone_span(id);
298-
}
294+
.push(id.clone());
299295
}
300296

301297
fn exit(&self, id: &span::Id) {
302298
if let Some(spans) = self.current_spans.get() {
303-
if spans.borrow_mut().pop(id) {
304-
self.try_close(id.clone());
305-
}
299+
spans.borrow_mut().pop(id);
306300
}
307301
}
308302

tracing-subscriber/src/registry/stack.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ pub(crate) struct SpanStack {
1818

1919
impl SpanStack {
2020
#[inline]
21-
pub(super) fn push(&mut self, id: Id) -> bool {
21+
pub(super) fn push(&mut self, id: Id) {
2222
let duplicate = self.stack.iter().any(|i| i.id == id);
2323
self.stack.push(ContextId { id, duplicate });
24-
!duplicate
2524
}
2625

2726
#[inline]

0 commit comments

Comments
 (0)