Friday, April 8, 2016

Bug with Mono in StringReader

There is a strange bug in StringReader which may affect your Unity games due to a bug in Unity.

I had intended to insert 100K entries to a dictionary in memory. I was reading those files from file in Unity as seen below.

However it took about 11 seconds to insert 100K entries into memory. First I was suspected with the special ternary tree I was using to store strings. After examining the problem; I found that problem was related with a mono bug. If your text file has UNIX endings (/n) problem occurs. If you replace all end lines with microsoft style (/r/n) problem disappears. Time decreased from 11 seconds to 0.2 seconds!

Meanwhile; in order to do changing line ending (and applying some other business related filters) I used Kotlin language for the first time and I was very happy to see such a simple and efficient language.