Skip to content

perf(internal/civisibility): cache SetTestFunc source metadata#4691

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 8 commits into
mainfrom
feat/civisibility-settestfunc-source-cache
Apr 24, 2026
Merged

perf(internal/civisibility): cache SetTestFunc source metadata#4691
gh-worker-dd-mergequeue-cf854d[bot] merged 8 commits into
mainfrom
feat/civisibility-settestfunc-source-cache

Conversation

@tonyredondo

Copy link
Copy Markdown
Member

What does this PR do?

Caches the source metadata used by (*tslvTest).SetTestFunc so each source file is parsed once per process instead of being reparsed on every call.

The change keeps the existing behavior intact while moving the AST work into a per-file cache:

  • preserves the same source tags, unskippable semantics, impacted-tests inputs, code-owner lookup, and debug log messages
  • keeps the current declaration-vs-literal matching rules, including the existing literal line-tolerance heuristic
  • adds regression tests for repeated lookups, repeated log emission, suite-level and declaration-level unskippable, negative parse caching, concurrent cache access, and declarations without bodies
  • resets the new cache in test helpers so package tests remain isolated

Motivation

Profiling internal/civisibility/integrations/gotesting consistently showed repeated go/parser.ParseFile work inside SetTestFunc as the main internal hotspot. This removes that repeated parsing without changing the observable behavior of the integration.

Validation run for this change:

  • go test ./internal/civisibility/integrations/...
  • go test ./internal/civisibility/integrations/gotesting/...
  • go test ./internal/civisibility/...
  • repeated local profiling of TestFlakyTestRetries=1 go test -cpuprofile=... -memprofile=... . in internal/civisibility/integrations/gotesting, confirming go/parser.ParseFile drops from a repeated hotspot to one-time metadata loading

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • New code is free of linting errors. You can check this by running make lint locally.
  • New code doesn't break existing tests. You can check this by running make test locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • All generated files are up to date. You can check this by running make generate locally.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild. Make sure all nested modules are up to date by running make fix-modules locally.

Unsure? Have a question? Request a review!

@tonyredondo
tonyredondo requested a review from a team as a code owner April 23, 2026 15:43
@datadog-official

datadog-official Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 98.51%
Overall Coverage: 61.12% (+0.09%)

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

@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: 01a6fd0071

ℹ️ 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 thread internal/civisibility/integrations/manual_api_sourcecache.go Outdated
@tonyredondo
tonyredondo requested a review from a team as a code owner April 23, 2026 16:27
@codecov

codecov Bot commented Apr 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.44961% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.81%. Comparing base (4dab362) to head (22fa2c3).

Files with missing lines Patch % Lines
...nal/civisibility/integrations/manual_api_ddtest.go 91.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
...ivisibility/integrations/manual_api_sourcecache.go 100.00% <100.00%> (ø)
internal/civisibility/utils/git.go 56.48% <100.00%> (-10.75%) ⬇️
...nal/civisibility/integrations/manual_api_ddtest.go 56.15% <91.66%> (-7.97%) ⬇️

... and 273 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pr-commenter

pr-commenter Bot commented Apr 23, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-04-24 15:51:36

Comparing candidate commit 681734c in PR branch feat/civisibility-settestfunc-source-cache with baseline commit 4dab362 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 271 metrics, 7 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 62de3fa into main Apr 24, 2026
190 of 192 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the feat/civisibility-settestfunc-source-cache branch April 24, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants