CSVWriter produces a new StringBuilder on each writeNext.
Moreover StringBuilder is preallocated in a wrong manner: let's say we have nextLine array of 2 items each of them of 10 chars,
StringBuilder sb = new StringBuilder(nextLine.length * 2);
preallocates just 4 bytes instead of 16 by default - so extra garbage load on builder expansion.
processLine creates new StringBuilder and after that converts to String - it is unnecessary - it could appends to the same sb.
One of the solutions how to drastically reduce the garbage pressure it to have private StringBuilder and reuse it, the other solution is to use BufferedWriter and appends immediately to it (instead of StringBuilder).
For the performance reasons I made my own BufferedWriter w/o extra sync because thread safely is not required for us.
I can provide patch.
Please send patch and I will run it through the unit test and performance
test it.
The next release is already full up but I will try and test it out for the
release after.
Scott :)
On Thu, Mar 31, 2016 at 3:55 AM, Dolzhenko Vladimir Alexandrovic bob_marlin@users.sf.net wrote:
--
Scott Conway
scott.conway@gmail.com
http://www.conwayfamily.name
Related
Feature Requests:
#76So - that's a jmh based benchmark
That's a patch implies idea of reusable StringBuilder
That's a patch implies idea of not thread safety BufferedWriter (avoid garbage pressure as well + avoid unnecessary copying from StringBuilder-String to Writer)
The Buffered writer is no longer needed because of the changes made in 3.8 where we are using the writer the user passed in instead of wrapping it in a PrintWriter.
But your reusedStringBuilder patch is what gave me pause. I personally have never tested openCSV in a multi-threaded environment though I have seen several questions early on asking if it supported threading. This patch would definitely force us to be single threaded because everything is sharing the same StringBuffer.
Vladimir I am going to have to think on this one.
Actually take that back - your change in Patch #57 took out the need for the StringBuilder by allowing the user to pass in their own Appendable and put the threadsafety issue into their hands <BG>.