Skip to content

Reduce agent startup matching overhead for loaded classes - #21033

Open
trask wants to merge 15 commits into
mainfrom
trask-bookish-spork
Open

trask wants to merge 15 commits into
mainfrom
trask-bookish-spork

Conversation

@trask

@trask trask commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Reduce startup matching work for already-loaded classes by rejecting impossible name/hierarchy matches before classloader-resource checks and full type matching. Possible matches still run the original matcher; unknown matchers and calls without a loaded class retain their existing behavior.

The benchmark tooling used for these measurements is in #21041.

Agent-added startup overhead on bare metal

The ordinary-agent startup benchmark showed a 325.0 ms / 5.19% reduction in agent-added startup overhead, from 6,263.5 ms to 5,938.5 ms.

Configuration Measured starts Median JVM startup Agent-added overhead
No agent 40 3,773.0 ms 0.0 ms
Agent without optimization 40 10,036.5 ms 6,263.5 ms
Agent with optimization 40 9,711.5 ms 5,938.5 ms

Overhead is each agent's median startup time minus the no-agent median. The percentage reduction uses the unoptimized agent's overhead as its denominator, not total application startup time. These are differences of pooled medians, not medians of paired per-round differences.

Run 1 and run 2 each measured 20 fresh JVM starts per configuration after discarding two starts per configuration. Their overhead reductions were 4.77% and 5.28%, respectively. Configurations ran serially in rotating order each round on the same official bare-metal host. The second run reused the first run's built artifacts.

All configurations used the same pinned Spring Boot image, JDK 25.0.1, two-CPU quota, 1 GiB memory limit, and 512 MiB heap. The no-agent control omitted -javaagent; both agents kept instrumentation and SDK enabled with exporters disabled. Filesystem/image caches were warm, and separate diagnostic JFR launches were excluded from timings.

The metric is JVM uptime sampled while producing the first successful /greeting response. The overhead therefore includes the agent's effects on application startup, not just time inside premain. Results apply to this fixture on a shared host, not every application.

Measured baseline e8417286f55 against optimized revision dfcbd7d2a24. Artifacts retain all observations, commands, hashes, host identity, and profiles.

trask and others added 4 commits October 27, 2026 12:21
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Bare-metal measurements did not confirm a startup improvement. Preserve the experiment on trask-startup-indexed-unproven-20261027.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-11-07 17:29 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Copilot AI 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.

🟢 Approval recommended

No active review issues block approval of the loaded-class matching optimization.

No open issues 🎉

What changed in this PR

Reduces javaagent startup matching overhead by filtering out impossible matches for already-loaded classes before classloader checks and full type matching.

Changes:

  • Caches loaded-class hierarchy names and uses them to prefilter recognized matchers.
  • Preserves original matching for possible matches, unknown matchers, and calls without a loaded class.
  • Adds tests covering name and hierarchy filtering, delegate evaluation, and fallback behavior.
File Description
javaagent-tooling/​src/​test/​java/​net/​bytebuddy/​agent/​builder/​AgentBuilderUtilTest.java Tests loaded-class filtering and preservation of original matching behavior.
javaagent-tooling/​src/​main/​java/​net/​bytebuddy/​agent/​builder/​AgentBuilderUtil.java Adds cached hierarchy names and wraps recognized matchers with a loaded-class prefilter.

Review effort: Balanced

trask and others added 3 commits October 27, 2026 17:13
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>

Copilot AI 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.

🟢 Approval recommended

No active review issues block approval of the loaded-class matching optimization.

No open issues 🎉

Review effort: Balanced

Co-authored-by: trask <218610+trask@users.noreply.github.com>

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the loaded-class matcher prefiltering change.

No open issues 🎉

Review effort: Balanced

Co-authored-by: trask <218610+trask@users.noreply.github.com>

Copilot AI 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.

🟢 Approval recommended

No active review issues were identified for the loaded-class matching optimization.

No open issues 🎉

Review effort: Balanced

Co-authored-by: trask <218610+trask@users.noreply.github.com>

Copilot AI 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.

🟢 Approval recommended

No active review issues block approval of the loaded-class matching prefilter change.

No open issues 🎉

Review effort: Balanced

Co-authored-by: trask <218610+trask@users.noreply.github.com>

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the change that reduces loaded-class matching overhead.

No open issues 🎉

Review effort: Balanced

@trask
trask marked this pull request as ready for review October 29, 2026 20:40
@trask
trask requested a review from a team as a code owner October 29, 2026 20:40

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants