I am sorry to say this, but I was looking at Bits implementation and found out that the only thing method "read_from" does is copying bytes in a loop. Guys, please !!! You never do it like this.
If you want to copy arrays use "System.arraycopy" but in this case you don't have to copy anything. You don't need a buffer to read from byte array. All you need to do is update some variables. This method should look like this:
public void read_from(final byte[] newbytes,
final int offset,
final int len)
{
bytes=newbytes;
bytePtr=offset;
bitPtr=0;
}
But then, why do you call it "read_from" ?
This class needs to be redesigned and refactored properly, as it is called very often (for each decoded block)
Regards,
Yatzooh
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you are looking into optimizing the code for maximum performance, I encourage you to refactor this code (although I doubt you will see any significant performance change, since the amount of time spent in that method is minimal), and submit it to me for inclusion.
Having said this, my priority when writing this code was ease of maintenance. The code is a port of the C Speex code to java. Wherever possible the code has been kept as close to the original C code as possible. That way, whenever Jean-Marc releases a new version of Speex, I can look at the diff, and bring over all the changes with as little problem as possible, because it is easy to find the code that he has modified.
I find that the small performance penalty that might be bourn from this is more then sufficiently compensated by the ease of maintenance of the project in the long run.
Marc
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have reduced unnecessary loops in Bits class and have sent you an e-mail with my modifications. I believe it will improve overall performance. Look in your inbox.
Regards,
Jacek
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am sorry to say this, but I was looking at Bits implementation and found out that the only thing method "read_from" does is copying bytes in a loop. Guys, please !!! You never do it like this.
If you want to copy arrays use "System.arraycopy" but in this case you don't have to copy anything. You don't need a buffer to read from byte array. All you need to do is update some variables. This method should look like this:
public void read_from(final byte[] newbytes,
final int offset,
final int len)
{
bytes=newbytes;
bytePtr=offset;
bitPtr=0;
}
But then, why do you call it "read_from" ?
This class needs to be redesigned and refactored properly, as it is called very often (for each decoded block)
Regards,
Yatzooh
If you are looking into optimizing the code for maximum performance, I encourage you to refactor this code (although I doubt you will see any significant performance change, since the amount of time spent in that method is minimal), and submit it to me for inclusion.
Having said this, my priority when writing this code was ease of maintenance. The code is a port of the C Speex code to java. Wherever possible the code has been kept as close to the original C code as possible. That way, whenever Jean-Marc releases a new version of Speex, I can look at the diff, and bring over all the changes with as little problem as possible, because it is easy to find the code that he has modified.
I find that the small performance penalty that might be bourn from this is more then sufficiently compensated by the ease of maintenance of the project in the long run.
Marc
I have reduced unnecessary loops in Bits class and have sent you an e-mail with my modifications. I believe it will improve overall performance. Look in your inbox.
Regards,
Jacek