Skip to content

Adapt type outline members lazily into exact-size arrays - #13743

Draft
dougqh wants to merge 1 commit into
masterfrom
dougqh/lazy-type-outline
Draft

dougqh wants to merge 1 commit into
masterfrom
dougqh/lazy-type-outline

Conversation

@dougqh

@dougqh dougqh commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Outlines parsed with ClassFile.outline no longer copy every field, method, and annotation into the TypeOutline up front. Members are adapted on first request, into exact-size arrays wrapped by ByteBuddy's Explicit lists (no copy), and the same immutable lists are returned on every call.

  • Thread safety without locks: racing first requests each build equal, immutable members, and one is published through a volatile field. The pending outline is cleared only after the members are published, so a thread never sees neither.
  • The other construction paths are unchanged: visitor parsing and loaded-class parsing still declare members one at a time; their lists are now created on first declaration instead of always.
  • New TypeOutlineTest (JUnit 5): adapted members match an independent ASM read of the same class (fields, methods, method and class annotations of interest); a type without members; repeated calls return the same lists; 16 threads racing the first access agree over 50 rounds.

Motivation

TypeOutline(ClassOutline) wrapped every member eagerly into default-sized, growing ArrayLists for every outlined type.

Measured on PetClinic startup, two agent builds from the same base commit:

master this PR
Startup (median of 7 interleaved runs) 4.959 s 4.966 s (neutral)
Allocated by the ready point (median of 3) 1,352 MB 1,320 MB (about -2.4%)

The gain is modest because laziness rarely gets to skip work today: 94% of outlined types (5,640 of 6,015) still have all their members adapted. Memoizer.doMemoize evaluates every registered field and method matcher against every declared member of every memoized type, including the whole supertype hierarchy. Most of this PR's saving comes from exact-size arrays replacing growing lists.

Data for a follow-up: member matching is almost all misses

Measured in the same PetClinic startup with a temporary counter build:

Registered matchers Decidable without building member objects Members evaluated Members that could match Hit rate
Fields 13 13 (all name-anchored) 14,646 5 0.03%
Methods 21 21: 9 name-anchored, 10 anchored on a method annotation, 1 name prefix, 2 declaredBy (the same for every member of a type, so they can be checked once per type) 69,483 44 (for the name-anchored matchers) 0.06%

Each startup builds about 84,000 ByteBuddy member objects and makes about 1.6 million matcher calls to find a few dozen members that matter. A prefilter in the memoizer (check member names against the 13 field and 11 method names matchers can match, check whether a method has any annotation of interest, and evaluate declaredBy once per type) would skip nearly all of that, using data ClassFile.outline already provides. I'd like to discuss that direction before proposing it; this PR is the uncontroversial first step.

Additional Notes

  • Formatting applied with spotlessApply; the outline tests pass, including OutlineTypeParserTest, TypeFactoryTargetBytecodeTest, and TypeFactoryForkedTest.

🤖 Generated with Claude Code

Outlines parsed with ClassFile.outline no longer copy every field, method,
and annotation into growing ArrayLists when the outline is created. Members
are adapted on first request into exact-size arrays wrapped by ByteBuddy's
Explicit lists, and the same immutable lists are returned on every call.

Racing first requests each build equal, immutable members and one is
published through a volatile field; no locking. Outlines built one member
at a time (visitor and loaded-class parsing) are unchanged, except that
their lists are created on first declaration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added comp: core Tracer core tag: performance Performance related changes 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 Dec 1, 2026
@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🎯 Code Coverage (details)
• Patch Coverage: 0.00%
• Overall Coverage: 63.57% (+2.17%)

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

@dd-octo-sts

dd-octo-sts Bot commented Dec 1, 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.86 s 14.74 s [+0.0%; +1.6%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.67 s 13.72 s [-1.0%; +0.3%] (no difference)
startup:petclinic:appsec:Agent 17.76 s 17.47 s [+0.8%; +2.6%] (maybe worse)
startup:petclinic:iast:Agent 17.56 s 17.12 s [-1.9%; +7.1%] (no difference)
startup:petclinic:profiling:Agent 17.47 s 17.22 s [+0.4%; +2.4%] (maybe worse)
startup:petclinic:sca:Agent 17.80 s 17.66 s [-0.1%; +1.7%] (no difference)
startup:petclinic:tracing:Agent 16.81 s 16.85 s [-1.4%; +0.9%] (no difference)

Commit: 662e391e · 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.

This branch has not been deployed

No deployments
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 tag: performance Performance related changes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant