When reviewing this wonderful StringBuilder replacement, I noticed the performance for Append() with string type is much worse compared to System.Text.StringBuilder.

The test code I'm using is:
int COUNT = 1000;
List<string> strings = new List<string>();
for (int i = 0; i < 100; i++)
strings.Add("123456789");
Profiler.BeginSample("Append/SharedStringBuilderScope()");
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for (int i = 0; i < COUNT; i++)
{
for (int j = 0; j < strings.Count; j++)
{
sb.Append(strings[j]);
}
sb.ToString();
sb.Clear();
}
}
Profiler.EndSample();
Profiler.BeginSample("Append/ZString.StringBuilder()");
for (int i = 0; i < COUNT; i++)
{
using (var sb = ZString.CreateStringBuilder())
{
for (int j = 0; j < strings.Count; j++)
{
sb.Append(strings[j]);
}
sb.ToString();
}
}
Profiler.EndSample();
Is this a known issue? Based on deep profiling in Unity, I noticed that the bottleneck was caused by explicit IntPtr casting. I'm not sure if this is just a bogus timing due to deep profiling, but making IL2CPP builds also shows it to be performing poorly vs System.Text.StringBuilder
When reviewing this wonderful StringBuilder replacement, I noticed the performance for Append() with string type is much worse compared to System.Text.StringBuilder.
The test code I'm using is:
Is this a known issue? Based on deep profiling in Unity, I noticed that the bottleneck was caused by explicit IntPtr casting. I'm not sure if this is just a bogus timing due to deep profiling, but making IL2CPP builds also shows it to be performing poorly vs System.Text.StringBuilder