Do we have plan to support ScopedValue rather than ThreadLocal?
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず io.opentelemetry.context.ThreadLocalContextStorage と、issue に記載されている JDK の仮想スレッドの動作を確認します。ScopedValue がコンテキストストレージの要件と互換性があるかを明らかにし、アプローチを比較するために必要なベンチマークまたはテストを特定します。完了とみなすには、コード変更だけでなく、文書化された設計上の決定または合意された実装計画が必要です。
索引モデルが issue の本文から書いたものです。
説明
I saw the impl heavily relies on ThreadLocal like io.opentelemetry.context.ThreadLocalContextStorage.
While in our LnP test against JDK virtual thread, we found threadlocal could be the bottleneck.
Is there any plan to switch to ScopedValue?
Here's also some comments from AI:
The Performance Overhead Sources
- Thread.currentThread() lookup: Each get()/set() needs to get the current thread. With virtual threads, this involves:
- Finding the carrier thread
- Looking up which virtual thread is currently mounted
- This has more indirection than with platform threads - Mounting/unmounting cost: When a virtual thread blocks (IO), it's unmounted. On resumption, there's overhead. ThreadLocal access
during this transition adds to the cost. - Potential JVM internal contention: While ThreadLocalMap itself is largely lock-free, some JVM implementations have shown
contention-like bottlenecks at scale due to:
- Internal hash map operations
- Memory barrier costs with millions of concurrent threads
The Reality Check
┌────────────────────────────────┬────────────────────────────────────────┐
│ Aspect │ Reality │
├────────────────────────────────┼────────────────────────────────────────┤
│ Traditional lock contention? │ No │
├────────────────────────────────┼────────────────────────────────────────┤
│ Per-operation overhead higher? │ Yes, marginally │
├────────────────────────────────┼────────────────────────────────────────┤
│ Scales to millions of threads? │ Debatable - depends on access patterns │
├────────────────────────────────┼────────────────────────────────────────┤
│ ScopedValue better? │ Yes, designed for virtual threads │
└────────────────────────────────┴────────────────────────────────────────┘
Recommendation
For new code with virtual threads, prefer ScopedValue (Java 21+) over ThreadLocal. It's semantics-matched to virtual thread model and
avoids some of the historical design choices in ThreadLocal that weren't made with millions of threads in mind.
If stuck with ThreadLocal, keep access patterns minimal and benchmark your specific use case.
- 主要言語
- Java
- スター
- 2.5k
- フォーク
- 1.1k
- 平均マージ
- 5日 11時間
- マージ済み PR(30日)
- 41
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
open-telemetry/opentelemetry-java のほかの issue
-
`B3PropagatorExtractorMultipleHeaders` allocates when headers are missing対応中かも @Eliot5566 が今日担当しました。 オープンBug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
open-telemetry/opentelemetry-java#9065 ·
メンテナーはふだん 3 日以内に返信
-
[incubator] ComposableProbabilitySampler does not validate ratio range対応中かも @eminfikret が 4 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
open-telemetry/opentelemetry-java#9046 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
-
PrometheusComponentProvider promotes all resource attributes when resource_constant_labels is empty ({})対応中かも @rooks-ns が 19 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
open-telemetry/opentelemetry-java#9014 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
Fix `otel.sdk.log.created` counting semantics対応中かも @anuraaga が 112 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
open-telemetry/opentelemetry-java#8688 ·
メンテナーはふだん 3 日以内に返信
-
SdkSpanBuilder drops invalid parent TraceState when IdGenerator.generatesRandomTraceIds() is true対応中かも @Eliot5566 が今日担当しました。 オープンBug SDK
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
open-telemetry/opentelemetry-java#9062 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
open-telemetry/opentelemetry-java の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
micronaut-projects/micronaut-core#14585 ·
メンテナーはふだん 1 日以内に返信
-
Mend: dependency security vulnerability untriaged
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
opensearch-project/cross-cluster-replication#1805 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 3 日以内に返信
-
feature request needs triage
難易度 1/5 1時間未満 初心者へのやさしさ 66/100
TeamNewPipe/NewPipe#14083 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
PCL-Community/PCL-CE#3907 ·
メンテナーはふだん 1 日以内に返信