Skip to content

ci: skip generated code when collecting coverage - #5773

Merged
ric-oliv merged 1 commit into
mainfrom
ci/skip-generated-code-coverage
Oct 22, 2026
Merged

ric-oliv merged 1 commit into
mainfrom
ci/skip-generated-code-coverage

Conversation

@ric-oliv

@ric-oliv ric-oliv commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Every test host in the build workflow spends about 35 seconds before it runs a single test. That's coverlet instrumenting Sentry.dll, and almost all of that time goes into code the regex source generator writes for us.

  • coverlet rewrites the SDK assemblies in each test host's output folder before the tests run, and nothing is reused between hosts.
  • For every branch it instruments, it rebuilds the list of instructions that have a sequence point by scanning the whole method again, in CecilSymbolHelper.FindClosestInstructionWithSequencePoint. The cost grows with instructions × sequence points × branches.
  • [GeneratedRegex] turns each pattern into an unrolled matcher. The crontab pattern in CrontabValidator becomes one TryMatchAtCurrentPosition method with 8,070 IL instructions, 682 conditional branches and 1,968 sequence points. The next biggest method in Sentry.dll has 708 instructions and 62 branches.
  • By instructions × branches, that one method is 5.5 million of the 6.1 million total across the 4,541 methods in Sentry.dll, so about 90% of the instrumentation cost. I measured this on the net10.0 Sentry.dll and its PDB from the packages CI built for 8333e3b.
  • The net48 hosts don't pay this, because generated regexes only exist on .NET 7 and later.

This PR passes ExcludeByAttribute=GeneratedCodeAttribute to the coverlet collector, so it skips anything a source generator marks as generated.

Locally, Sentry.Hangfire.Tests on net10.0 took 39.8 and 41.1 seconds with coverage, and 5.4 and 9.9 seconds with the exclusion. In CI, each .NET test host used to wait 15 to 53 seconds before xUnit started, while the net48 hosts waited 4 to 7.

Here's the Test step on this PR, compared with the median of 35 main PR runs since October 15:

Test step main PRs, median This PR
.NET (win-x64) 13.9 min 6.3 min
.NET (linux-x64) 13.9 min 3.7 min
.NET (macos) 13.6 min 3.6 min
.NET (linux-musl-x64) 11.3 min 3.5 min
.NET (win-arm64) 8.8 min 4.2 min
.NET (linux-arm64) 7.2 min 2.4 min
.NET (linux-musl-arm64) 7.2 min 2.4 min
  • The win-x64 job took 40.9 minutes against a median of 50.8, win-arm64 took 40.1 against 47.6, and macOS took 54.6 against 66.8.
  • Each of these legs ran the same test runs and the same passed and skipped counts as main at the base commit, run 39744888536. On win-x64 that's 70 test runs and 14,630 passed tests, on macOS it's 59 test runs and 11,451 passed tests, and nothing failed.
  • The first macOS attempt hit a network error in "Upload build logs", Failed to CreateArtifact: Unable to make request: ENOTFOUND, so its numbers come from a rerun of that job. A rerun only repeats macOS and the two AOT jobs after it, so this run has no clean end-to-end time. Counting the 51 seconds before the .NET jobs started on the first attempt, it adds up to about 66.5 minutes against a median of 77.4 for main.

What changes in the coverage report:

  • The generated files leave the raw coverlet report: the RegexGenerator.g.cs files and the SentryJsonContext.*.g.cs files from the System.Text.Json source generator.
  • Hand-written code keeps the same coverage, including the hand-written halves of partial classes like EmailValidator.
  • Codecov doesn't change. The generated files live under obj/ and aren't in the repo, so Codecov never counted them. With all uploads in, it shows the same 528 files and 19,579 lines as main, at 76.12% for both, with 14,905 lines hit against 14,904.
  • CodeCoverage.runsettings already excludes GeneratedCodeAttribute for the Microsoft collector, so coverlet now matches it.

The same tests run, and nothing else in the workflow changes.

#skip-changelog

coverlet instruments the SDK assemblies again in every test host, and for each branch it
rescans the whole method for sequence points. [GeneratedRegex] turns the crontab pattern into
one TryMatchAtCurrentPosition method with 8,070 IL instructions, 682 branches and 1,968
sequence points, about 90% of the instruction x branch cost across Sentry.dll. That costs
about 35 s of CPU per test host before any test runs.

Excluding [GeneratedCode] skips the generated regex matchers and the System.Text.Json
source-generated context. Hand-written code keeps the same coverage, and
CodeCoverage.runsettings already excludes the same attribute for the Microsoft collector.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.12%. Comparing base (8333e3b) to head (5b536b5).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5773   +/-   ##
=======================================
  Coverage   76.12%   76.12%           
=======================================
  Files         528      528           
  Lines       19579    19579           
  Branches     3829     3829           
=======================================
+ Hits        14904    14905    +1     
+ Misses       3792     3791    -1     
  Partials      883      883           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ric-oliv
ric-oliv marked this pull request as ready for review October 22, 2026 13:01
@ric-oliv
ric-oliv requested a review from bitsandfoxes October 22, 2026 13:01
@github-actions github-actions Bot added the risk: low PR risk score: low label Oct 22, 2026
@ric-oliv
ric-oliv enabled auto-merge (squash) October 22, 2026 13:02
@bitsandfoxes

Copy link
Copy Markdown
Contributor

⏩ ⏩

@ric-oliv
ric-oliv merged commit bd407cf into main Oct 22, 2026
@ric-oliv
ric-oliv deleted the ci/skip-generated-code-coverage branch October 22, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: low PR risk score: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants