Skip to content

Reuse no-op scopes in the OTel bridge - #1646

Merged
jonatan-ivanov merged 1 commit into
mainfrom
otel-reuse-noop-scopes
Nov 4, 2026
Merged

jonatan-ivanov merged 1 commit into
mainfrom
otel-reuse-noop-scopes

Conversation

@shakuzen

@shakuzen shakuzen commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Redundant span scopes and clearing an already empty context currently allocate wrappers even though closing them does nothing. Reuse CurrentTraceContext.Scope.NOOP and a private SpanInScope singleton, while preserving actual context clearing, restoration and publisher behavior.

Replace the existing scope test's private-wrapper casts with current-context/restoration assertions. Add coverage for clearing native baggage/data without an active span and closing a redundant scope while another span is current.

Validation

  • Full repository check passes: 608 passed, nine existing skips, including 187 OTel tests.
  • The initial full run hit the known Brave/Reactor flake; a subsequent full check and clean integration rerun passed.
  • Benchmark compilation/style checks and git diff --check pass.

Local benchmarks against main

Operation Source Main ns/op PR ns/op Main B/op PR B/op
currentTraceContextScope 5.37 4.23 16 0
emptyScope 3.40 0.93 16 0
inlinedTracerScope 4.00 4.00 0 0
realTracerScope 15.34 15.31 120 120
tracerScope 6.09 4.04 32 0

Returned-scope cases let the result escape; inlinedTracerScope covers ordinary fully inlined usage, where HotSpot already eliminates allocation. realTracerScope is the control for an actual attachment/restoration. The change removes the escaping no-op wrappers without a measured change in that control.

JMH 1.37, OTel 1.67.0, Java 25.0.4.1, Apple M5 Pro/macOS arm64; valid non-recording native spans. One worker, fixed 512 MiB G1 heap, three independent forks/version with alternating order; three 500 ms warmups and five 500 ms measurements. Values are means of fork means.

Return the existing facade no-op scope for redundant and empty native
scopes, and reuse a stateless SpanInScope when no attachment is needed.
Preserve clearing, restoration and publisher behavior.

Assert scope behavior without casting to private wrappers. Cover clearing
native baggage without a span and closing a redundant scope while another
span is current. Benchmark escaping, inlined and real scope operations.

Signed-off-by: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com>
@shakuzen shakuzen added enhancement New feature or request performance Issues related to general performance module: bridge-otel labels Nov 4, 2026
@shakuzen shakuzen added this to the 1.8.0-RC2 milestone Nov 4, 2026
@jonatan-ivanov
jonatan-ivanov merged commit dce46fd into main Nov 4, 2026
7 checks passed
@jonatan-ivanov
jonatan-ivanov deleted the otel-reuse-noop-scopes branch November 4, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request module: bridge-otel performance Issues related to general performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants