perf(internal/civisibility): cache testing field offsets#4698
Conversation
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: cc02dae | Docs | Datadog PR Page | Give us feedback! |
Codecov Report❌ Patch coverage is Additional details and impacted files
🚀 New features to boost your workflow:
|
BenchmarksBenchmark execution time: 2026-04-27 15:10:09 Comparing candidate commit cc02dae in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 240 metrics, 8 unstable metrics.
|
5de8153
into
main
What does this PR do?
Adds a runtime-validated offset cache for the private Go
testingfields 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
SetTestFuncsource 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
make lintlocally.make testlocally.make generatelocally.make fix-moduleslocally.Tests run:
git diff --checkBypass=true go test ./internal/civisibility/integrations/gotesting -run 'TestGetFieldPointerFrom|TestGetBenchmarkPrivateFields' -count=1go test ./internal/civisibility/integrations/gotesting/...go test ./internal/civisibility/integrations/...