Skip to content

refactor(constraints): drop pooled ThreadStatic StringBuilder in ToString - #614

Merged
samtrion merged 1 commit into
mainfrom
fix/stryker-constraintbase-threadstatic-builder
Oct 29, 2026
Merged

samtrion merged 1 commit into
mainfrom
fix/stryker-constraintbase-threadstatic-builder

Conversation

@samtrion

@samtrion samtrion commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

In the latest mutation run of this repo (score 77.21%: 229 mutants created, 52 compile errors, 5 NoCoverage, 41 ignored, 26 survived, 105 killed), ConstraintBase.ToString contributes mutants that can never be killed: survivors for "Null coalescing remove left" (_builder ?? new ...) and for the builder.Capacity > DefaultCapacity comparison (3 mutants), plus a NoCoverage block removal on the shrink branch. These per-file counts come from the HTML/JSON report; the log only contains the totals above.

Root cause

ToString uses a [ThreadStatic] pooled StringBuilder with capacity trimming, which is a micro-optimization on a diagnostic path. Pooled and fresh builders are indistinguishable from outside, so the behaviour is only observable via the private static field.

Change

ToString now uses new StringBuilder(). The static field, constant, try/finally and the S2696 pragma are removed. Output is unchanged.

Before / After

Run: https://github.com/dailydevops/fluentvalue/actions/runs/40804699089

metric before after
Mutation score 77.21% 80.15%
Created 229 222
Compile errors 52 52
NoCoverage 5 4
Ignored 41 39
Survived 26 22
Killed 105 105
Mutation step duration n/a 1m14s

Result: 4 survivors and 1 NoCoverage fewer, killed unchanged, as expected (per-file figures were not re-extracted; the totals match the predicted delta exactly). The 2 NoCoverage string mutants on the [Obsolete(error: true)] throw members remain and are out of scope for this PR.

Risk / what this does not change

Behaviour of ToString is identical (all 531 unit tests pass on net8.0 and net10.0). A new builder is allocated per call; this is a diagnostic path. The Obsolete Equals/GetHashCode mutants are untouched.

…ring

The thread-static builder with capacity trimming is a micro-optimization on a
diagnostic ToString path. Its effect is only observable through the private
static field, so mutation testing cannot confirm it works (survivors on the
null-coalescing and capacity comparison, no coverage on the shrink branch).
Use a plain StringBuilder instead.
@samtrion
samtrion requested a review from a team as a code owner October 29, 2026 02:09
@samtrion
samtrion requested a review from benwirren October 29, 2026 02:09
@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.25%. Comparing base (b5aad10) to head (6510613).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #614      +/-   ##
==========================================
+ Coverage   98.54%   99.25%   +0.71%     
==========================================
  Files          22       22              
  Lines         274      267       -7     
  Branches       43       41       -2     
==========================================
- Hits          270      265       -5     
+ Misses          1        0       -1     
+ Partials        3        2       -1     

☔ 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.

@samtrion
samtrion merged commit 86636ac into main Oct 29, 2026
13 checks passed
@samtrion
samtrion deleted the fix/stryker-constraintbase-threadstatic-builder branch October 29, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant