What is the best way to concatenate string to create an interaction logging console?

I need to display user interaction in a simulation, in a console-looking way. E.g, xterm, conEmu, etc.

I am currently using…

void UpdateUserInteraction(string userInput) {
     consoleText += userInput.ToString() + "

";
}

… to concatenate strings, where consoleText is the text content of a label.

After 1000+ concatenation, everything sluggish and stop eventually.
Now, my question, is there a better way to concatenate strings to simulate a console?

First thing you might want to look at and see if it helps at all is the redundant casting of userInput to a string using the .ToString() method. This is wasting processor time because it is converting a string to a string unnecessarily, so just do this:

void UpdateUserInteraction(string userInput) 
{
     consoleText += userInput + "

";
}

Additionally, the problem may exist with the GUI implementation in Unity itself. It is notoriously slow because the entire GUI has to be redrawn every time OnGUI() gets called, which is potentially multiple times per frame.

I believe that the intended use of the StringBuilder class would be to define the stringBuilder outside of your function. This would then allow you to use the .append method to add strings to the string builder by reference rather than assigning more memory to them, and also to avoid reinstantiating the StringBuilder each iteration.

If you need to refresh the contents within the StringBuilder just call the .Clear method.

This may marginally improve the performance of your app.
This post is a bit late but I hope it is helpful for others who are looking into this.

Also there is a nice manual entry available here that explains this in more detail: http://docs.unity3d.com/Manual/UnderstandingAutomaticMemoryManagement.html

Use StringBuilder class instead of + concat operator. It is much faster.
source: http://malideveloper.arm.com/documentation/developer-guides/arm-guide-unity-enhancing-mobile-games/

Use gstring http://forum.unity3d.com/threads/gstring-gc-free-string-for-unity.338588/