File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
dd-trace-core/src/main/java/datadog/trace/core/scopemanager Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -391,6 +391,8 @@ public Context swap(Context context) {
391391
392392 static final class ScopeStackThreadLocal extends ThreadLocal <ScopeStack > {
393393
394+ private final ScopeStack [] fastStacks = new ScopeStack [2048 ]; // This should be tuned
395+
394396 private final ProfilingContextIntegration profilingContextIntegration ;
395397
396398 ScopeStackThreadLocal (ProfilingContextIntegration profilingContextIntegration ) {
@@ -401,6 +403,41 @@ static final class ScopeStackThreadLocal extends ThreadLocal<ScopeStack> {
401403 protected ScopeStack initialValue () {
402404 return new ScopeStack (profilingContextIntegration );
403405 }
406+
407+ @ Override
408+ public ScopeStack get () {
409+ final long id = Thread .currentThread ().getId ();
410+ if (id >= 0 && id < this .fastStacks .length ) {
411+ ScopeStack ret = fastStacks [(int ) id ];
412+ if (ret == null ) {
413+ ret = initialValue ();
414+ fastStacks [(int ) id ] = ret ;
415+ }
416+ return ret ;
417+ } else {
418+ return super .get ();
419+ }
420+ }
421+
422+ @ Override
423+ public void set (ScopeStack value ) {
424+ final long id = Thread .currentThread ().getId ();
425+ if (id >= 0 && id < this .fastStacks .length ) {
426+ fastStacks [(int ) id ] = value ;
427+ } else {
428+ super .set (value );
429+ }
430+ }
431+
432+ @ Override
433+ public void remove () {
434+ final long id = Thread .currentThread ().getId ();
435+ if (id >= 0 && id < this .fastStacks .length ) {
436+ fastStacks [(int ) id ] = null ;
437+ } else {
438+ super .remove ();
439+ }
440+ }
404441 }
405442
406443 private void scheduleRootIterationScopeCleanup (ScopeStack scopeStack , ContinuableScope scope ) {
You can’t perform that action at this time.
0 commit comments