Repository navigation
refactor(constraints): drop pooled ThreadStatic StringBuilder in ToString - #614
Merged
Merged
Conversation
…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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.ToStringcontributes mutants that can never be killed: survivors for "Null coalescing remove left" (_builder ?? new ...) and for thebuilder.Capacity > DefaultCapacitycomparison (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
ToStringuses a[ThreadStatic]pooledStringBuilderwith 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
ToStringnow usesnew 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
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
ToStringis 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 ObsoleteEquals/GetHashCodemutants are untouched.