Repository navigation
Reduce virtual-thread context-propagation overhead on park/unpark #11893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gh-worker-dd-mergequeue-cf854d
merged 21 commits into
master
from
andrea.marziali/vthread-context-perf
Sep 23, 2026
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
74bb831
Reduce virtual-thread context-propagation overhead on park/unpark
amarziali c597d97
Preserve old implementation when legacy manager is disabled
amarziali 7dbcd5c
reduce diff
amarziali bc943bd
various suggestinos
amarziali 62fdca4
remove exposing clearContext on the interface
amarziali 02fe769
Adjust javadoc
amarziali 8200fa4
remove unuseful test
amarziali bcaf39d
account cws
amarziali 53ce731
Add correctness feedback
amarziali eb15343
Address virtual-thread review feedback
amarziali 8405709
Skip virtual-thread profiler rebinding when unnecessary
amarziali 47514a5
Test ddprof virtual-thread context rebinding
amarziali f9ff353
Clarify ddprof context rebinding
amarziali 73b3814
Correct virtual-thread context benchmark
amarziali 76c8e26
Retain per-mount context propagation on JDK 21
amarziali dc7d4b3
Test virtual thread profiler context at first run
amarziali a779af8
Merge branch 'master' into andrea.marziali/vthread-context-perf
amarziali 38445d5
Merge branch 'master' into andrea.marziali/vthread-context-perf
amarziali 7c23d77
Apply batched suggestions from code review
amarziali 3095c72
Apply suggestions and bench correctness
amarziali e917d52
spotless
amarziali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ng-ddprof/src/test/java/com/datadog/profiling/ddprof/DatadogProfilingIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package com.datadog.profiling.ddprof; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.Answers.CALLS_REAL_METHODS; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.mockStatic; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
| import static org.mockito.Mockito.withSettings; | ||
|
|
||
| import datadog.context.Context; | ||
| import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
| import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext; | ||
| import datadog.trace.bootstrap.instrumentation.api.ProfilerContext; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.MockedStatic; | ||
|
|
||
| class DatadogProfilingIntegrationTest { | ||
| @Test | ||
| void rebindsSpanContextAndClearsRootContext() { | ||
| DatadogProfiler profiler = mock(DatadogProfiler.class); | ||
| when(profiler.operationNameOffset()).thenReturn(5); | ||
| when(profiler.resourceNameOffset()).thenReturn(6); | ||
|
|
||
| try (MockedStatic<DatadogProfiler> profilerFactory = mockStatic(DatadogProfiler.class)) { | ||
| profilerFactory.when(DatadogProfiler::newInstance).thenReturn(profiler); | ||
|
|
||
| AgentSpanContext spanContext = | ||
| mock(AgentSpanContext.class, withSettings().extraInterfaces(ProfilerContext.class)); | ||
| ProfilerContext profilerContext = (ProfilerContext) spanContext; | ||
| when(profilerContext.getRootSpanId()).thenReturn(11L); | ||
| when(profilerContext.getSpanId()).thenReturn(22L); | ||
| when(profilerContext.getTraceIdHigh()).thenReturn(33L); | ||
| when(profilerContext.getTraceIdLow()).thenReturn(44L); | ||
| when(profilerContext.getOperationName()).thenReturn("operation"); | ||
| when(profilerContext.getResourceName()).thenReturn("resource"); | ||
|
|
||
| AgentSpan span = mock(AgentSpan.class, CALLS_REAL_METHODS); | ||
| when(span.spanContext()).thenReturn(spanContext); | ||
|
|
||
| DatadogProfilingIntegration integration = new DatadogProfilingIntegration(); | ||
| assertTrue(integration.isThreadContextBindingRequired()); | ||
|
|
||
| integration.setContext(span); | ||
| verify(profiler).setTraceContext(11L, 22L, 33L, 44L, 5, "operation", 6, "resource"); | ||
|
|
||
| integration.setContext(Context.root()); | ||
| verify(profiler).clearTraceContext(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...tdog/trace/instrumentation/java/lang/jdk21/VirtualThreadApiInstrumentationForkedTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package testdog.trace.instrumentation.java.lang.jdk21; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import datadog.trace.bootstrap.instrumentation.java.lang.VirtualThreadState; | ||
| import datadog.trace.test.junit.utils.config.WithConfig; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Runs the {@link VirtualThreadApiInstrumentationTest} cases with the legacy context manager | ||
| * disabled, so {@code VirtualThreadState} takes the swap path instead of seed-once. Forked because | ||
| * the legacy-context-manager choice is captured once per JVM. | ||
| */ | ||
| @WithConfig(key = "legacy.context-manager.enabled", value = "false") | ||
| class VirtualThreadApiInstrumentationForkedTest extends VirtualThreadApiInstrumentationTest { | ||
| @DisplayName("test per-mount path is selected for the new context manager") | ||
| @Test | ||
| void testPerMountPathSelected() { | ||
| assertTrue(VirtualThreadState.usePerMountContext()); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...tdog/trace/instrumentation/java/lang/jdk21/VirtualThreadCwsInstrumentationForkedTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package testdog.trace.instrumentation.java.lang.jdk21; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import datadog.trace.bootstrap.instrumentation.java.lang.VirtualThreadState; | ||
| import datadog.trace.test.junit.utils.config.WithConfig; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** Verifies that CWS retains scope-listener notifications on every virtual-thread mount. */ | ||
| @WithConfig(key = "cws.enabled", value = "true") | ||
| class VirtualThreadCwsInstrumentationForkedTest extends VirtualThreadApiInstrumentationTest { | ||
| @DisplayName("test per-mount path is selected for CWS") | ||
| @Test | ||
| void testPerMountPathSelected() { | ||
| assertTrue(VirtualThreadState.usePerMountContext()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.