Commit d992fcd
Move thread-ownership optimization into OptimizedTagMap
Per review feedback, move the lock-skipping optimization from
DDSpanContext into OptimizedTagMap itself. This keeps the optimization
invisible to callers — DDSpanContext no longer needs synchronized blocks
around tag operations, and developers adding new tag operations don't
need to think about locking.
OptimizedTagMap now has a volatile Thread ownerThread field. Core methods
(getAndSet, getAndRemove, getEntry, putAll, forEach, copy, etc.) check
ownership: owner thread skips the lock, non-owner threads synchronize
and permanently transition to shared mode.
DDSpanContext changes: removed all 27 synchronized(unsafeTags) blocks,
added setOwnerThread(current) in constructor, transitionToShared()
delegates to TagMap.
Also adds @threads(8) JMH benchmark variants and 5 new concurrency
tests (mixed read/write, fuzz, value consistency, finish race,
concurrent metrics).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent d664ab2 commit d992fcd
File tree
7 files changed
+650
-298
lines changed- dd-trace-core/src
- jmh/java/datadog/trace/core
- main/java/datadog/trace/core
- test/java/datadog/trace/core
- internal-api/src/main/java/datadog/trace/api
7 files changed
+650
-298
lines changedLines changed: 55 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
89 | 126 | | |
90 | 127 | | |
91 | 128 | | |
| |||
103 | 140 | | |
104 | 141 | | |
105 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
106 | 161 | | |
0 commit comments