Instrument LambdaMetafactory and preserve Runnable lambda identity during context propagation - #12346
Instrument LambdaMetafactory and preserve Runnable lambda identity during context propagation#12346amarziali wants to merge 18 commits into
Conversation
|
@DataDog review |
|
🎯 Code Coverage (details) 🔗 Commit SHA: a721063 | Docs | View more details | Give us feedback! |
There was a problem hiding this comment.
On JDK 8 and JDK 11, the new structure matcher requires a field that does not exist. The lambda transformer does not run, and Runnable lambdas still use wrappers.
🤖 Datadog Autotest · Commit 054841c · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
054841c to
5742c20
Compare
|
@DataDog review |
There was a problem hiding this comment.
More details
The PR instruments generated Runnable lambdas so executor propagation keeps task identity, with supported JDK paths and a Graal build guard. This update fixes the earlier JDK 8 and 11 samBase mismatch and adds no new finding; the documented concurrent-reuse limitation remains, and no review finding is open.
🤖 Datadog Autotest · Commit 5655a6f · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
What Does This Do
Instrument
Runnablelambda classes when they are generated byLambdaMetafactory, allowing executor context propagation to attach state directly to the lambda instead of creating aRunnableWrapper.This is primarily a functional improvement: avoiding the wrapper preserves the submitted task’s identity while retaining the existing context-propagation behavior.
Notable changes
java.lang.Runnable; the mechanism can later be extended to interfaces such asCallable.dd.trace.lambda.enabled=falseavailable as an opt-out.Known limitation
Concurrent submissions of the same
Runnablelambda instance share a single continuation slot. As with other field-injected Runnable implementations, only one pending context can be retained, so overlapping submissions may lose or misassociate context propagation.Previously, wrapped lambdas had per-submission state. This limitation is most relevant to reusable singleton or stateless lambdas submitted concurrently; lambdas created per operation are unlikely to encounter it.
Benchmarks
Benchmarks were run with
dd.benchmark.enabled=true.Spring Boot startup
A Spring Boot 3.3 Petclinic-style application was measured on Temurin 17 across 15 interleaved runs:
The 95% confidence interval for the paired difference was ±43.9 ms, so the measured startup difference was indistinguishable from run-to-run noise.
The application generated approximately 1,600 lambda classes. Of those, 22 exact-
Runnablecandidates entered the transformer and 8 were modified.JMH results
run(), JDK 17run(), JDK 25The linkage cost is paid once when a matching lambda call site is created. Unrelated lambda interfaces take the fast trie-rejection path. The direct-run benchmark intentionally uses a nearly empty Runnable, making the relative percentage appear larger than the very small absolute overhead.
GC profiling confirms an 8-byte increase for instrumented capturing Runnable lambda instances due to the injected state field. This is the expected heap tradeoff and may be more visible in applications that retain large numbers of Runnable objects.
Motivation
Additional Notes
Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]