Background
First, I have a text file (CSV) with a few columns and hundred thousands of rows. The total file size is 10MB. I used resource with Unity so it loads as Text
The related code is:
TextAsset txtData = Resources.Load("data.csv") as TextAsset;
string txt = txtData.text;
strReader = new StringReader(txt);
string line0 = strReader.ReadLine();
....
currentLine =strReader.ReadLine();
while (true) {// if last line is nothing we quit
var values = currentLine.Split(',');
try {
float x = (float)Convert.ToSingle(values[colX]);
float y = (float)Convert.ToSingle(values[colY]);
float z = (float)Convert.ToSingle(values[colZ]);
float w = (float)Convert.ToSingle(values[colSize]);
runningList.Add(v1);
}catch(Exceptoion e){
}
currentLine = strReader.ReadLine();
}
Problem
It was found that the reading plus parsing is slow so that it affects the Unity visual effect. So I used log file to see. I count time for every 500 rows. Strange enough, the last group takes 12ms (500 rows), the second from last takes 20ms, the time is linearly increasing to 1.5-1.7 seconds for the first group.
More Info
When Unity is drawing at 90 Hz, I am using a thread to read the string and parse the data.
Question
Where should I look for problems? I used Unity resource, string reader, split, parsing to float. Where is the cause and is there a way to improve?
It looks strange as the time reduces.
Update
after I used file stream reader, it is 2ms each group. So it is Unity TextAsset?