Skip to content

Add an interactive Hashtable internals demo - #12334

Draft
bric3 wants to merge 1 commit into
masterfrom
bdu/add-hashtable-internals-demo
Draft

Add an interactive Hashtable internals demo#12334
bric3 wants to merge 1 commit into
masterfrom
bdu/add-hashtable-internals-demo

Conversation

@bric3

@bric3 bric3 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Adds a standalone animated demo for datadog.trace.util.Hashtable. Each step keeps the abridged Java code, bucket array, linked entry chains, hash masking, and iterator state synchronized.

The demo contains five sections with a suggested scenario for each:

  • Single key (D1)
    • Suggested scenario: insert same-hash and masked collisions, spread keys across other buckets, follow get through the linked chain, then mutate the returned entry in place.
  • Composite key (D2)
    • Suggested scenario: store route counters keyed by HTTP method and status without allocating a composite key, then look up and update one route.
  • Counter pattern (getOrCreate and forEach)
    • Suggested scenario: follow CardinalityLimitReporter from a miss through creator invocation and insertion, reuse the entry on a hit, summarize with a context-passing consumer, then clear the table.
  • Chain surgery (insertOrReplace and remove)
    • Suggested scenario: traverse a collision chain with MutatingBucketIterator, expose its predecessor/current/next references in a separate band, replace a middle entry, then unlink the tail in constant time.
  • Custom table (Hashtable.Support)
    • Suggested scenario: follow an AggregateTable across reporting cycles, leave one aggregate stale, miss on a new key at the logical cap, evict through a cursor-resumed sweep, then admit the new aggregate.

A final API map compares when to use D1, D2, or Support and summarizes their contracts.

Motivation

Hashtable is deliberately smaller and more specialized than HashMap, but several important mechanics are easy to miss during code review: an array slot points to a linked entry chain, bucket masking does not establish key identity, getOrCreate invokes its creator only after a miss, mutating iterators retain splice pointers, and custom callers own capacity and eviction policy.

The demo makes those relationships visible and gives reviewers concrete scenarios for the main APIs and their production usage.

Additional Notes

  • The demo is standalone and does not change production behavior or add dependencies.
  • Controlled hashes and an eight-bucket view keep the diagrams readable while preserving the relevant mechanics.
  • The embedded JavaScript passes syntax checks, and the lookup, capacity, mutation, and lifecycle states were rendered in Firefox.

Contributor Checklist

Jira ticket: N/A

@bric3 bric3 added comp: core Tracer core type: documentation tag: no release notes Changes to exclude from release notes tag: ai generated Largely based on code generated by an AI or LLM labels Aug 28, 2026
@datadog-official

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Aug 28, 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.77 s 14.80 s [-1.3%; +0.8%] (no difference)
startup:insecure-bank:tracing:Agent 13.72 s 13.70 s [-1.0%; +1.3%] (no difference)
startup:petclinic:appsec:Agent 17.55 s 16.92 s [-0.8%; +8.2%] (no difference)
startup:petclinic:iast:Agent 17.49 s 17.53 s [-1.0%; +0.5%] (no difference)
startup:petclinic:profiling:Agent 17.44 s 17.36 s [-0.8%; +1.6%] (no difference)
startup:petclinic:sca:Agent 17.45 s 17.16 s [+0.6%; +2.8%] (maybe worse)
startup:petclinic:tracing:Agent 16.54 s 16.61 s [-1.4%; +0.6%] (no difference)

Commit: 63634d0d · 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.

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: documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant