Repository navigation
Add @PerfContract meta-annotation and @SuppressPerfContract (AI perf review) #12647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gh-worker-dd-mergequeue-cf854d
merged 6 commits into
master
from
dougqh/perf-contract-suppress
Sep 29, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
673fe41
Add @PerfContract meta-annotation and @SuppressPerfContract
dougqh b045658
Teach perf-review's @NoEscape check about @SuppressPerfContract
dougqh a24671a
Move @PerfContract and @SuppressPerfContract to datadog.perfcontract
dougqh 68d21c5
Add CODEOWNERS entry for datadog.perfcontract
dougqh b60ef78
Fix stale marker refs, simplify javadocs, mark existing markers @Perf…
dougqh ca99c17
Add @SuppressPerfContract as an accepted NoEscape exception path
dougqh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
internal-api/src/main/java/datadog/perfcontract/PerfContract.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package datadog.perfcontract; | ||
|
|
||
| import datadog.trace.api.function.NoEscape; | ||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * Marks an annotation as a performance contract for documentation and static analysis. Contract | ||
| * annotations describe performance constraints, such as the retention rule documented by {@link | ||
| * NoEscape}, without changing runtime behavior. | ||
| * | ||
| * <p>Tools use this meta-annotation to discover contracts and recognize {@link | ||
| * SuppressPerfContract} exemptions. This annotation defines no rule itself. | ||
| * | ||
| * <p>{@link RetentionPolicy#CLASS} lets tools discover contracts in dependency class files without | ||
| * exposing them through runtime reflection. | ||
| */ | ||
|
dougqh marked this conversation as resolved.
|
||
| @Documented | ||
| @Retention(RetentionPolicy.CLASS) | ||
| @Target(ElementType.ANNOTATION_TYPE) | ||
| public @interface PerfContract {} | ||
56 changes: 56 additions & 0 deletions
56
internal-api/src/main/java/datadog/perfcontract/SuppressPerfContract.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package datadog.perfcontract; | ||
|
|
||
| import java.lang.annotation.Annotation; | ||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
|
dougqh marked this conversation as resolved.
|
||
| * Suppresses findings from one or more annotations marked with {@link PerfContract} on the | ||
| * annotated declaration. Suppressions document deliberate exceptions and have no runtime effect. | ||
| * | ||
| * <p>{@link #value} identifies contracts by class, so stale names fail to compile. {@link #reason} | ||
| * records why the exception is intentional and must not be blank. | ||
| * | ||
| * <p>This annotation may also annotate another annotation type to define a reusable suppression. | ||
| * Applying that annotation is equivalent to applying {@code @SuppressPerfContract} directly and | ||
| * uses the meta-annotation's reason. Prefer direct use for declaration-specific reasons. Do not | ||
| * suppress a case that the contract already defines as compliant. | ||
| * | ||
| * <p>The target excludes local variables because declaration annotations on them are not stored in | ||
| * class files. {@link ElementType#ANNOTATION_TYPE} enables reusable suppressions. | ||
| * | ||
| * <p>{@link RetentionPolicy#CLASS} makes suppressions visible to classfile-based tools without | ||
| * exposing them through runtime reflection. | ||
| * | ||
| * <p><b>Checker contract.</b> A finding is suppressed when the declaration has either: | ||
| * | ||
| * <ul> | ||
| * <li>this annotation with the relevant contract in {@link #value} and a non-blank {@link | ||
| * #reason}; or | ||
| * <li>an annotation that carries such a {@code @SuppressPerfContract} annotation. | ||
| * </ul> | ||
| * | ||
| * <p>Every class in {@code value} must itself be annotated {@link PerfContract}; otherwise the | ||
| * suppression is invalid. A terse reason is valid if it is non-blank. | ||
| */ | ||
| @Documented | ||
| @Retention(RetentionPolicy.CLASS) | ||
| @Target({ | ||
| ElementType.TYPE, | ||
| ElementType.FIELD, | ||
| ElementType.METHOD, | ||
| ElementType.CONSTRUCTOR, | ||
| ElementType.PARAMETER, | ||
| ElementType.ANNOTATION_TYPE | ||
| }) | ||
| public @interface SuppressPerfContract { | ||
|
|
||
| /** The perf-contract marker(s) being suppressed, by class reference. */ | ||
| Class<? extends Annotation>[] value(); | ||
|
|
||
| /** Why this exception is deliberate and reviewed, not an oversight. */ | ||
| String reason(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.