SocketInputStream.read() takes 70% of the time
Hey all. I have a multithreaded program that reads some data over the net, and I have been profiling it with hprof to get the performance up.
Basically, my data format is an ASCII number followed by a newline, then that many bytes of data following. The data itself is XML.
my input function is essentially broken into 3 parts:
read 1 byte at a time until i hit a newline.
read x bytes into a buffer
convert the buffer into an XML object.
Profiling tells me that out of 42K samples, 30K are in the first part, 6K are in the second, and 4K are in the third. The 30K all come from SocketInputStream.read(). This doesn't seem right at all to me. I have included the first function below:
private String readUntil(char stop_char)
throws IOException
{
StringBuilder new_string =new StringBuilder();
while (true){
int in = input_stream.read();
if (in == -1 || in == stop_char){
break;
}
new_string.append((char)in);
}
return new_string.toString();
}
Any help that you can provide is greatly appreciated! Thanks!

