StringBuffer class has considerable performance issues

Aug 2, 2010 at 2:03 PM
If you have a JSON file with 700kb string field (that's one json property with considerable amount of data), it will take about 10 minutes or so to process. The issue is StringBuffer class. After replacing StringBuffer with StringBuilder, what used to take 10 minutes is now done instantly. Main performance loss comes from reallocating and copying data each time buffer needs to be expanded. Buffer increases each time by 4000 or so bytes, and keeps copying/reallocating until it reaches 700.000 in this fashion.. which is of course very slow.
Aug 2, 2010 at 11:24 PM

What version are you using? An older version of Json.NET had a bug in StringBuffer when working with large strings.

Aug 3, 2010 at 2:14 PM
Hello James, this indeed was the case. It is one of the older versions. I updated the StringBuffer class and now its working great. Sorry to have wasted your time :)