Skip to content

Improve codeowners lookup performance#12058

Open
daniel-mohedano wants to merge 1 commit into
masterfrom
daniel.mohedano/improve-codeowners-lookup-performance
Open

Improve codeowners lookup performance#12058
daniel-mohedano wants to merge 1 commit into
masterfrom
daniel.mohedano/improve-codeowners-lookup-performance

Conversation

@daniel-mohedano

@daniel-mohedano daniel-mohedano commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Improves CODEOWNERS lookup performance in Test Optimization.

The change removes several per-lookup allocations and adds adaptive indexing for large CODEOWNERS sections:

  • Matchers consume the original path String instead of creating a char[]
  • Owners are deduplicated once during parsing instead of during every lookup
  • Each lookup still returns a fresh mutable owner list
  • Ownership and exclusion rules are managed independently
  • Large rule sets are indexed by their first two fixed path segments
  • Patterns without a safe fixed prefix remain in a linear fallback
  • Rule order still determines precedence across indexed and fallback matches

The index activates only when a rule set contains at least 512 entries and at least half can be indexed. Smaller rule sets retain the linear lookup path. When the index activates, already parsed entries are moved into their buckets using index keys computed during parsing. Patterns are not reparsed.

Motivation

CODEOWNERS parsing happens once during repository initialization, but ownership lookup runs for every test and test suite. Large CODEOWNERS files can therefore consume measurable CPU and allocate hundreds of bytes per lookup.

The first implementation indexed every file. Benchmarks across Java projects showed that indexing small rule sets could add latency. The final implementation uses an adaptive gate so only large, indexable rule sets pay the indexing cost.

Additional Notes

The original benchmarking was performed against an input which contained 6,679 lines and 5,596 entries. Lookups were sampled up to 30,000 tracked paths.

Measurement Linear Optimized Change
Average lookup time 58.290 us/lookup 12.631 us/lookup 78.3% lower
p50 lookup time 60.672 us 10.624 us 82.5% lower
p95 lookup time 102.144 us 30.272 us 70.4% lower
p99 lookup time 112.640 us 37.376 us 66.8% lower
Lookup allocation 483.144 B/lookup 108.914 B/lookup 77.5% lower
Time to parse the whole file 3.832 ms 3.950 ms 3.1% higher
Allocation while parsing 7.97 MiB 8.13 MiB 2.0% higher

Given the nature of the repository (multi-language monorepo), other projects were also benchmarked to account for specific patterns in codeowners definition for Java-centric repositories:

Project profile Entries (fixed / fallback) Index active Linear time Optimized time Linear allocation Optimized allocation
Large polyglot monorepo 5,596 (5,346 / 250) Yes 58.290 us/lookup 12.631 us/lookup (↓78.3%) 483.144 B/lookup 108.914 B/lookup (↓77.5%)
Large Java service monorepo 1,228 (1,177 / 51) Yes 19.661 us/lookup 11.269 us/lookup (↓42.7%) 559.060 B/lookup 111.873 B/lookup (↓80.0%)
Java build-tool project 95 (86 / 9) No 1.626 us/lookup 1.604 us/lookup (↓1.4%) 494.806 B/lookup 48.063 B/lookup (↓90.3%)
Java multi-module project 165 (130 / 35) No 15.272 us/lookup 15.181 us/lookup (↓0.6%) 474.052 B/lookup 48.045 B/lookup (↓89.9%)
Small Java service 12 (9 / 3) No 1.327 us/lookup 1.206 us/lookup (↓9.1%) 410.820 B/lookup 48.004 B/lookup (↓88.3%)
Small test project 28 (27 / 1) No 0.794 us/lookup 0.761 us/lookup (↓4.2%) 437.652 B/lookup 51.904 B/lookup (↓88.1%)
Small Android project 3 (0 / 3) No 2.143 us/lookup 2.152 us/lookup (↑0.4%) 515.021 B/lookup 48.006 B/lookup (↓90.7%)

test-environment-trigger: skip

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@daniel-mohedano daniel-mohedano added type: feature Enhancements and improvements comp: ci visibility Continuous Integration Visibility labels Jul 23, 2026
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
Patch Coverage: 86.14%
Overall Coverage: 57.16% (-0.39%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: b45a9a7 | Docs | Datadog PR Page | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Jul 23, 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 13.91 s 13.91 s [-0.6%; +0.7%] (no difference)
startup:insecure-bank:tracing:Agent 12.96 s 12.98 s [-0.9%; +0.7%] (no difference)
startup:petclinic:appsec:Agent 16.49 s 16.92 s [-6.8%; +1.8%] (no difference)
startup:petclinic:iast:Agent 16.89 s 17.00 s [-1.4%; +0.2%] (no difference)
startup:petclinic:profiling:Agent 16.67 s 16.87 s [-2.3%; +0.0%] (no difference)
startup:petclinic:sca:Agent 17.02 s 16.79 s [+0.2%; +2.5%] (maybe worse)
startup:petclinic:tracing:Agent 15.82 s 15.72 s [-5.3%; +6.6%] (unstable)

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

@daniel-mohedano daniel-mohedano added the tag: ai generated Largely based on code generated by an AI or LLM label Jul 24, 2026
@daniel-mohedano

Copy link
Copy Markdown
Contributor Author

@codex review

@daniel-mohedano

Copy link
Copy Markdown
Contributor Author

/datadog autotest review

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot 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.

Datadog Autotest: PASS

More details

The adaptive index retains the key lookup invariants on inspection: unsafe-prefix rules stay in the fallback list, and source order decides between fallback and keyed matches. Execution could not complete because Gradle 9.6.1 is not cached and the sandbox blocks the wrapper download.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Datadog Autotest · Commit b45a9a7 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: b45a9a70b4

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@daniel-mohedano
daniel-mohedano marked this pull request as ready for review July 24, 2026 11:50
@daniel-mohedano
daniel-mohedano requested a review from a team as a code owner July 24, 2026 11:50

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot 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.

Datadog Autotest: PASS

More details

Large-rule-set matching preserved the prior implementation across directory, recursive, wildcard, fixed-prefix, and malformed-separator shapes. Indexed ownership/exclusion lookup and fallback precedence also returned the expected owners, so no user-facing regression was identified.

Was this helpful? React 👍 or 👎

📊 Validated against 101 scenarios · Open Bits AI session

🤖 Datadog Autotest · Commit b45a9a7 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b45a9a70b4

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +247 to +248
if (firstSeparator >= 0) {
return new String(c, prefixStart, position - prefixStart);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep trailing-slash rules out of the fixed-prefix index

In large sections where the index activates, a two-segment trailing-slash rule such as /services/api/ is bucketed under services/api, but the existing matcher still treats that rule as a plain prefix because no end-of-segment matcher is appended for trailing slashes. This makes behavior depend on file size: with 511 prior indexable entries services/api-v2/Test.java is matched by the linear scan, while with 512 entries the indexed lookup only checks the services/api-v2 bucket and returns no owner; exclusions have the same issue. Either keep these trailing-slash patterns in the fallback until the matcher semantics are tightened, or make the matcher and index agree.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: ci visibility Continuous Integration Visibility tag: ai generated Largely based on code generated by an AI or LLM type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants