Should the compiler detect and optimize slow code constructions?
I think it is more important to educate the developer that certain constructions just are bad practice. Like doing multiple memory/object allocations inside a loop.
That is exactly the difference between String and StringBuilder class in .NET. This was also the example the guy on Franklins.NET podcast asked about. String class compared to the StringBuilder concatenation results in String class doing a lot of more memory allocations.
I am at the moment playing with comparing the String to my own immutable string. It seems as most operations can be optimized to reuse the buffer of another string.