On 2021-03-01 Brett Okken wrote:
> > One thing that confuses me in your version is the special handling
> > of the first byte:
> >
> >         buf[pos++] = buf[back++];
> >         --left;
> >
> > If there are two bytes to copy, then one will be copied above and
> > the other with arraycopy later. If there are more bytes to copy and
> > distance is very small, incrementing "back" above can mean that an
> > extra arraycopy call might be needed in the loop because the first
> > copy will be one byte smaller.
> >
> > I understand that it might help when there is just one byte to
> > repeat because then the while-loop will be skipped. In all other
> > situations it sounds like that the special handling of the first
> > byte would in theory be harmful. Note that I don't doubt your test
> > results; I already saw with the CRC64 code that some changes in the
> > code can affect performance in weird ways.  
> The image1.dcm is the most impacted by this optimization. Again, this
> file is basically a large greyscale bmp. This results in a significant
> number of single byte repeats. Optimizing for the single byte improves
> performance in that file by 3-5%, while having smaller effects on the
> other 2 files (ihe_ovly_pr.dcm slightly slower, large.xml slightly
> faster)

OK, that is an interesting test case.

> I agree your approach is more readable. From your version of it, I was
> expecting that simplicity in reading to translate into better
> performance.
> This latest version actually does appear to do that. The image1.dcm
> performance matches my version and the other 2 are a bit faster.
> Adding the single byte optimization still speeds up image1.dcm (~8ms,
> ~2%) and large.xml (~3ms, 2%), while slowing ihe_ovly_pr.dcm (~.008ms,
> ~1%).
> Version 3 is better for all 3 files.

With these results I now plan to include version 3 in the next release.
It sounds that the single-byte optimization has a fairly small effect.
Omitting it keeps the code a tiny bit simpler.

I have committed the change. I think xz-java.git should now be almost
ready for a release. I just need to add NEWS and bump the version

Thanks for your help!

Lasse Collin  |  IRC: Larhzu @ IRCnet & Freenode

Reply via email to