Skip to content

Add all-native ThreadContextBenchmark and refresh its report - #904

Merged
jbachorik merged 1 commit into
mainfrom
run-otel-thread
Oct 26, 2026
Merged

jbachorik merged 1 commit into
mainfrom
run-otel-thread

Conversation

@jbachorik

Copy link
Copy Markdown
Collaborator

What does this PR do?:

Benchmark (ns/op) JNI (pre-2026-04-08) ByteBuffer All-native
setContextFull 37.5 17.1 31.3
setAttrCacheHit 172.4 28.1 60.9
spanLifecycle 226.4 43.8 91.2

Motivation:

The report measured only the ByteBuffer implementation, on a laptop. #696 removed that implementation and its benchmark, so the current write path had no benchmark and no current numbers.

The all-native implementation is about 2x slower than the ByteBuffer implementation. It is 1.2x to 2.8x faster than the JNI implementation, but the JNI put() did different work per call (it kept the custom attributes). None of the three implementations shows false sharing from 1 to 4 threads.

Additional Notes:

  • The report contains the source of the historical benchmark, with a link to the original file at 86367c704. ThreadContext no longer exists, so that source cannot be in the tree.
  • The ported benchmark wraps its route counter. The historical benchmark used counter++ % 5, which throws after 2^31 calls on one thread. The benchmark also stops the profiler and deletes its JFR file in a trial @TearDown.
  • The report documents two problems in the benchmark setup:
    • The Gradle jmh {} block overrides the class annotations.
    • stresstests.jar contains both the debug and the release libjavaProfiler under the same entry name.
      The procedure runs the jar directly, with the release library only.
  • The report does not explain the 2x cost against the ByteBuffer implementation. It lists the candidate costs and recommends a profile.
  • Review: two passes of the Claude Code /code-review (high). Sphinx was unavailable. The first pass found 10 issues, and this PR fixes all of them. The second pass ran over the fixed diff and found 7 issues. This PR fixes 4 of them: the javadoc and the procedure now name the jar Main defaults, the report notes that the JNI comparison covers different work, and the cost model is marked as an estimate. 3 are declined:
    • The two findings against the implementation-history and historical-results sections. Comparing implementations is the purpose of the report.
    • The finding about a shared spanLifecycle helper. The committed benchmark stays identical to the code that produced the numbers.

How to test the change?:

  • :ddprof-stresstest:compileJmhJava and :ddprof-lib:qualityChecks pass.
  • Follow "Reproducing the Numbers" in the report: build :ddprof-stresstest:jmhJar, keep only the release library in the jar, and run java -jar bench.jar 'ThreadContextBenchmark' -f 2 -wi 3 -w 1s -i 5 -r 2s -tu ns -bm avgt.
  • The numbers in the report come from that procedure on an AWS Xeon Platinum 8175M host (Ubuntu 22.04, Temurin 25.0.3).

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a security review (run the dd:platform-security-review
    skill, or file a request via the PSEC review form).
    bewaire also runs automatically on every PR.
  • This PR doesn't touch any of that.
  • JIRA: [JIRA-XXXX]

Unsure? Have a question? Request a review!

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jbachorik jbachorik added the AI label Oct 26, 2026
@datadog-datadog-prod-us1-2

This comment has been minimized.

@jbachorik
jbachorik marked this pull request as ready for review October 26, 2026 11:56
@jbachorik
jbachorik requested a review from a team as a code owner October 26, 2026 11:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T11:59:03.366903Z a92490c Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

The benchmark calls match the current native context API, and the reproduction procedure accounts for runner defaults and duplicate debug/release library entries. The reported timings were not independently rerun.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit a92490c

@dd-octo-sts

dd-octo-sts Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #40316770477 | Commit: 8040fdc | Duration: 18m 11s (longest job)

✅ All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - ✅ - -
8-ibm - ✅ - -
8-j9 ✅ ✅ - -
8-librca - - ✅ ✅
8-orcl - ✅ - -
11 - ✅ - -
11-j9 ✅ ✅ - -
11-librca - - ✅ ✅
17 ✅ ✅ - -
17-graal ✅ ✅ - -
17-j9 ✅ ✅ - -
17-librca - - ✅ ✅
21 ✅ ✅ - -
21-graal ✅ ✅ - -
21-librca - - ✅ ✅
25 ✅ ✅ - -
25-graal ✅ ✅ - -
25-librca - - ✅ ✅

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-10-26 12:01:10 UTC

@jbachorik
jbachorik merged commit a7cb131 into main Oct 26, 2026
121 of 135 checks passed
@jbachorik
jbachorik deleted the run-otel-thread branch October 26, 2026 12:03
@github-actions github-actions Bot added this to the 1.53.0 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant