Home Dashboard Directory Help
Search

String.Concat Slow in .NET 4.5 by Ehrys


Status: 

Active


2
1
Sign in
to vote
Type: Bug
ID: 780770
Opened: 3/6/2013 2:40:20 AM
Access Restriction: Public
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description


When analysing the performance of different String manipulation methods, String.Concat came out drastically slower than the same code compiled for .NET 3.5

Please see this article I wrote: http://www.daniweb.com/software-development/csharp/code/448050/performance-of-string-operations

It seems to be the way that the IL is generated. It is subtly different to the same code compiled for .NET 3.5. Why does the same level of optimisation no longer apply in 4.5?
Details
Sign in to post a comment.
Posted by Richard Deeming on 6/27/2013 at 8:55 AM
As pointed out in the comments on your article, running the code in .NET 3.5 does not produce the same result. The String.Concat<T>(IEnumerable<T>) overload was added in .NET 4.0; in 3.5, you're calling the String.Concat(object) overload.

In 4.5, you're creating a string containing the 10000 characters; in 3.5, you're creating a string which contains "System.Collections.Generic.List'1[System.Char]" - the result of calling ToString on the list you've passed in, rather than on each item in the string.

If you change the code to use the overloads available in 3.5, you will see similar performance between the methods, with String.Concat taking noticeably longer than the other methods.
Posted by Microsoft on 3/27/2013 at 11:12 AM
Thank you for your feedback. We are not going to be able to address this issue in our next release due to other priorities.

You can workaround the issue by casting the string to object.

Regards,
Immo Landwerth
.NET Framework team
Posted by Microsoft on 3/6/2013 at 9:41 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 3/6/2013 at 2:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.