Skip to content

Change checkSourceLengthRule to use Span.IsWhiteSpace instead of Stri…#854

Open
Numpsy wants to merge 1 commit intofsprojects:masterfrom
Numpsy:source_length_span
Open

Change checkSourceLengthRule to use Span.IsWhiteSpace instead of Stri…#854
Numpsy wants to merge 1 commit intofsprojects:masterfrom
Numpsy:source_length_span

Conversation

@Numpsy
Copy link
Copy Markdown
Contributor

@Numpsy Numpsy commented May 3, 2026

…ng.Trim

String.Trim can allocate a new string on each call, whereas Span.IsWhiteSpace() shouldn't allocate at all.

Just a thought when looking at some Span related things.
If I run the existing benchmark app using the rule set which is enabled during the SelfCheck part of the CI build then I get this with the current code

| Method         | Mean    | Error    | StdDev   | Gen0       | Gen1       | Gen2      | Allocated |
|--------------- |--------:|---------:|---------:|-----------:|-----------:|----------:|----------:|
| LintParsedFile | 1.442 s | 0.0155 s | 0.0145 s | 43000.0000 | 13000.0000 | 3000.0000 | 726.17 MB |

And this afterwards

| Method         | Mean    | Error    | StdDev   | Gen0       | Gen1       | Gen2      | Allocated |
|--------------- |--------:|---------:|---------:|-----------:|-----------:|----------:|----------:|
| LintParsedFile | 1.454 s | 0.0094 s | 0.0073 s | 42000.0000 | 13000.0000 | 3000.0000 | 722.76 MB |

A small change improvement given the total allocations, but also a small change so I thought it'd still be useful.

…ng.Trim

String.Trim can allocate a new string on each call, whereas Span.IsWhiteSpace() shouldn't allocate at all.
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