Skip to content

perf(internal/civisibility): cache testing field offsets#4698

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
feat/gotesting-reflection-offset-cache
Apr 27, 2026
Merged

perf(internal/civisibility): cache testing field offsets#4698
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
feat/gotesting-reflection-offset-cache

Conversation

@tonyredondo

Copy link
Copy Markdown
Member

What does this PR do?

Adds a runtime-validated offset cache for the private Go testing fields used by the CI Visibility gotesting integration.

The hot helpers now resolve the testing.T, testing.B, testing.common, output writer, chatty printer, and context matcher layouts once per process. When the runtime layout matches the expected shape, repeated calls use cached offsets instead of resolving private fields by name through reflection. If a required layout check fails, the code falls back to the existing reflection implementation.

This also adds regression coverage and microbenchmarks for the new fast paths, including validation that pointer-word fields are actually pointer-like before they can be dereferenced.

Motivation

Profiling the flaky-retry gotesting scenario showed repeated private-field reflection as the next visible CI Visibility hot path after caching SetTestFunc source metadata. The goal is to reduce repeated reflection overhead while preserving behavior across supported Go versions and falling back safely on unexpected runtime layouts.

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.

Tests run:

  • git diff --check
  • Bypass=true go test ./internal/civisibility/integrations/gotesting -run 'TestGetFieldPointerFrom|TestGetBenchmarkPrivateFields' -count=1
  • go test ./internal/civisibility/integrations/gotesting/...
  • go test ./internal/civisibility/integrations/...

@datadog-official

datadog-official Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 74.78%
Overall Coverage: 61.15% (-0.05%)

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

@codecov

codecov Bot commented Apr 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.93688% with 122 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.87%. Comparing base (749408d) to head (cc02dae).

Files with missing lines Patch % Lines
...civisibility/integrations/gotesting/reflections.go 72.00% 50 Missing and 20 partials ⚠️
...ility/integrations/gotesting/reflection_offsets.go 79.76% 27 Missing and 25 partials ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
...ility/integrations/gotesting/reflection_offsets.go 79.76% <79.76%> (ø)
...civisibility/integrations/gotesting/reflections.go 59.13% <72.00%> (-17.86%) ⬇️

... and 275 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.

@tonyredondo
tonyredondo marked this pull request as ready for review April 27, 2026 15:09
@tonyredondo
tonyredondo requested a review from a team as a code owner April 27, 2026 15:09
@pr-commenter

pr-commenter Bot commented Apr 27, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-04-27 15:10:09

Comparing candidate commit cc02dae in PR branch feat/gotesting-reflection-offset-cache with baseline commit 749408d in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 240 metrics, 8 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 5de8153 into main Apr 27, 2026
192 of 193 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the feat/gotesting-reflection-offset-cache branch April 27, 2026 15:56
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.

3 participants