Skip to content

Add a Cursor toolbox type and walk FlatHashtable buckets with it - #13451

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 6 commits into
masterfrom
dougqh/toolbox-cursor
Nov 17, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 6 commits into
masterfrom
dougqh/toolbox-cursor

Conversation

@dougqh

@dougqh dougqh commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Adds datadog.trace.util.Cursor<T>, a toolbox traversal type: next() advances and returns the next element, or null when there are none left.

for (E e = cursor.next(); e != null; e = cursor.next()) { ... }
  • FlatHashtable.cursor(...): general and Entry-specialized overloads beside the existing iterator(...) ones. The cursors and the iterators share one traversal core (HashTraversal). The look-ahead hasNext() needs lives only in the iterator subclasses, so the cursors carry none and need no priming.
  • Hashtable.cursor(buckets), D1.cursor(), D2.cursor(): a whole-table cursor, the external form of forEach, with an iterate_hashtable_cursor variant in HashtableD1Benchmark and HashtableD2Benchmark.
  • IdStore.Cursor now extends the toolbox type; its shape was already the same. The nested name is kept, so the dense store's cursor (Add a dense known-tag store behind an experimental flag (dense store - part 8) #13004) needs no change.
  • Benchmark: cursor_general and cursor_specialized variants in FlatHashtableIteratorBenchmark.
  • AGENTS.md: a code convention to prefer a Cursor to a hand-written Iterator for new traversals.

Motivation

An Iterator has to compute the next element in hasNext() and hold it until next(), so its implementations carry a look-ahead field, an end flag, and priming in the constructor (see FlatHashtable's old iterator, which deferred priming to the subclass constructors). A cursor keeps only its position, so it is easier to write, and it is at least as fast as the iterator it replaces. Against forEach it trades some speed for ease of use: the loop is the caller's, so results can be carried out of it in locals, it can stop early, and two sources can be walked together. This is the first step toward cursor-based iteration for TagMap, replacing Iterable<EntryReader>.

Results

FlatHashtableIteratorBenchmark, MacBook M1, Zulu 17, 3 forks, poisoned hashOf profile, -prof gc. The master column is master's iterator on the same machine.

ops/s master this PR: iterator this PR: cursor
general 17.8M 18.1M 19.8M
specialized 44.5M 46.1M 46.7M

All variants are allocation-free.

HashtableD1Benchmark / HashtableD2Benchmark iteration, same machine, 8 threads, 3 forks, 2 s iterations:

ops/µs forEach cursor HashMap entrySet()
D1 46.4 ± 2.9 40.8 ± 0.4 19.9 (40 B/op)
D2 47.6 ± 0.7 45.0 ± 2.0 19.5 (40 B/op)

forEach stays the fastest full walk, 5–12% ahead of the cursor: the whole walk runs inside the table as one nested loop. The cursor is the replacement for Iterator, not for forEach; Cursor's Javadoc says when to use which.

Additional Notes

  • Wrapping a cursor in an iterator was tried first and dropped: each walk allocated 40 B. With an adapter holding the cursor, C2 inlined everything (nextWith and hashOf included) but didn't scalar-replace the cursor, a second object whose fields change in the caller's loop. Typing the adapter's field as the concrete cursor class didn't help. Sharing the traversal by inheritance keeps each walk to one object. Cursor's Javadoc records this: share a base class on hot paths; a wrapper is fine elsewhere.
  • Cursor is not @Confined: an adapter or wrapper has to keep its cursor in a field. Whether a cursor's elements can be kept depends on the element type: TagMap.EntryReader carries its own confinement (Add @Confined correctness contract for call- and frame-confined types #12997).
  • Not yet adopted: Hashtable's iterators, HashSupport.BucketWalker and Strings.SplitIterator are the next candidates. TagMap gets a public cursor after the dense store (Add a dense known-tag store behind an experimental flag (dense store - part 8) #13004) lands.

🤖 Generated with Claude Code

A cursor's next() advances and returns the next element, or null when
done, so a traversal needs no look-ahead: an Iterator's implementation
has to compute the next element in hasNext() and hold it until next().

FlatHashtable gets cursor() overloads beside iterator(). Both share one
traversal core; the look-ahead lives only in the iterator subclasses.
Wrapping a cursor in an iterator was tried first: C2 didn't
scalar-replace the pair, so each walk allocated 40 bytes.

IdStore.Cursor now extends the toolbox type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added comp: core Tracer core tag: no release notes Changes to exclude from release notes type: refactoring tag: ai generated Largely based on code generated by an AI or LLM labels Nov 13, 2026
@dougqh

dougqh commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T20:06:49.515586Z b7cea4d 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 405709677c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 58.99% (-1.53%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 26e2203 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.04 s 13.97 s [-0.3%; +1.2%] (no difference)
startup:insecure-bank:tracing:Agent 12.97 s 12.98 s [-0.7%; +0.6%] (no difference)
startup:petclinic:appsec:Agent 17.80 s 17.57 s [+0.5%; +2.2%] (maybe worse)
startup:petclinic:iast:Agent 17.45 s 17.75 s [-2.6%; -0.8%] (maybe better)
startup:petclinic:profiling:Agent 17.29 s 17.48 s [-2.3%; +0.1%] (no difference)
startup:petclinic:sca:Agent 17.72 s 17.64 s [-0.4%; +1.4%] (no difference)
startup:petclinic:tracing:Agent 16.66 s 16.86 s [-2.3%; -0.1%] (maybe better)

Commit: 26e22034 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

dougqh and others added 3 commits November 13, 2026 14:42
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hashtable.cursor(buckets), D1.cursor() and D2.cursor() walk every entry
as a Cursor: the external form of forEach. The D1 and D2 benchmarks get
an iterate_hashtable_cursor arm beside forEach and HashMap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh marked this pull request as ready for review November 16, 2026 20:01
@dougqh
dougqh requested review from a team as code owners November 16, 2026 20:01
@dougqh
dougqh requested review from AlexeyKuznetsov-DD and mhlidd and removed request for a team November 16, 2026 20:01

@datadog-prod-us1-4 datadog-prod-us1-4 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 cursor’s runtime behavior and reported allocation and throughput results remain unverified; this assessment is based on static inspection of the cursor and iterator changes.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit b7cea4d

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, Codex found couple of very minor issues.

@pr-commenter

pr-commenter Bot commented Nov 17, 2026

Copy link
Copy Markdown

LLM Validation

LLM Validation Gate — java-agent-instructions

✅ PASS

  • No blocking-case regressions; the quality change is within noise (baseline/candidate confidence intervals overlap).

6 case(s) · quality 80.9 → 81.7 (+0.8) · win-rate 51% [49%–54%]

Details — analysis and per-case results

Analysis

Changed instruction file(s): AGENTS.md.

No safety or blocking-case regressions across 6 case(s). Overall pairwise win-rate 51% [49%–54%], quality +0.8 — see the verdict above for whether that clears the noise band.

Results

  • Pairwise win-rate: 51% [49%–54%] — candidate's share of blind comparisons (90% CI; spanning 50% = no clear difference)
  • Overall quality: 80.9 → 81.7 (/100, +0.8)
  • Bad signals introduced (advisory): 0
  • Candidate criteria coverage (advisory): 23/27 (85%) — expected_criteria the candidate met; does not affect the gate
  • Blocking-case regressions: 0

Cases

Case Mode Quality Δ Win-rate (90% CI) Safety
java-core-validation-001 warn +1.1 58% [45%–72%] ok
java-unit-test-conventions-001 warn -0.6 50% [50%–50%] ok
java-premain-safety-001 warn +0.3 50% [50%–50%] ok
java-ci-download-guidance-001 warn +2.2 50% [50%–50%] ok
java-documentation-only-validation-001 warn +0.3 50% [50%–50%] ok
java-existing-spock-maintenance-001 warn +1.4 50% [50%–50%] ok

Per-dimension scores, token usage, latency, and estimated cost are in the CI job logs.

@dougqh

dougqh commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-17 21:35:41 UTC ℹ️ Start processing command /merge


2026-11-17 21:35:48 UTC ℹ️ MergeQueue: Pull request is not mergeable yet

It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.

  • Run /code blockers to see what is blocking it.
  • Run /remove to cancel it.

2026-11-17 22:25:12 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-11-17 23:23:53 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 820cdd1 into master Nov 17, 2026
685 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the dougqh/toolbox-cursor branch November 17, 2026 23:23
@github-actions github-actions Bot added this to the 1.70.0 milestone Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants