Skip to content

perf(Core/SourceLength): swap AsSpan with IsNullOrWhiteSpace#859

Merged
knocte merged 1 commit into
fsprojects:masterfrom
knocte:wip/stringIsNullOrWhiteSpaceInsteadOfAsSpan
Jun 5, 2026
Merged

perf(Core/SourceLength): swap AsSpan with IsNullOrWhiteSpace#859
knocte merged 1 commit into
fsprojects:masterfrom
knocte:wip/stringIsNullOrWhiteSpaceInsteadOfAsSpan

Conversation

@knocte
Copy link
Copy Markdown
Collaborator

@knocte knocte commented Jun 5, 2026

Recent PR[1] changed this hot-path from Trim().Length<>0 to AsSpan().IsWhiteSpace() and while the latter allocates less, it took actually longer to execute according to the contributor's own benchmark analysis.

Using String.IsNullOrWhiteSpace seems better here, because it shouldn't allocate either (vs Trim()) while it avoids calling AsSpan(), and the poor-man measurement stick I have so far is GitHub's CI runs: 3 jobs with the old codebase were slower than 1 job with this change.

[1] #854

Recent PR[1] changed this hot-path from `Trim().Length<>0` to
`AsSpan().IsWhiteSpace()` and while the latter allocates less,
it took actually longer to execute according to the contributor's
own benchmark analysis.

Using String.IsNullOrWhiteSpace seems better here, because it
shouldn't allocate either (vs `Trim()`) while it avoids calling
`AsSpan()`, and the poor-man measurement stick I have so far is
GitHub's CI runs: 3 jobs with the old codebase were slower than
1 job with this change.

[1] fsprojects#854
@knocte knocte force-pushed the wip/stringIsNullOrWhiteSpaceInsteadOfAsSpan branch from 3eeda59 to 8b1cfeb Compare June 5, 2026 10:43
@knocte knocte merged commit 84f8ce3 into fsprojects:master Jun 5, 2026
8 checks passed
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