Skip to content

Conversation

@WhiteBlackGoose
Copy link
Contributor

This is useful for example for string.Join, where most people would do string.Join("", blabla) to join strings without any delimiter, but it has a small performance penalty compared to string.Join(null, blabla)

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Sep 2, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Sep 2, 2025
@stephentoub
Copy link
Member

stephentoub commented Sep 2, 2025

This makes all non-empty inserts more expensive in exchange for making empty appends a tad cheaper. Can you share data that demonstrates that's a worthwhile tradeoff? My expectation is it would not be, that it's much more common to append non-empty strings.

@neon-sunset
Copy link
Contributor

neon-sunset commented Sep 2, 2025

A cheaper way to handle this could be by detecting an empty separator upfront and deferring to .Concat. I don't see this being handled on the path to JoinCore so presume it's not done at the moment: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs#L879-L908

@MihaZupan
Copy link
Member

Join("", ...) seems suprisingly common for some reason:

That seems like it could be an analyzer instead

@EgorBo
Copy link
Member

EgorBo commented Sep 3, 2025

IsKnownConstant might help as well

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

@teo-tsirpanis teo-tsirpanis removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 7, 2025
@jeffhandley
Copy link
Member

Closing the PR, replaced by an analyzer proposal: Analyzer Proposal: Suggest String.Concat instead of String.Join with an empty separator (#122889)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Runtime community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants