peter-lawrey / Java-Chronicle

Java Indexed Record Chronicle
1.22k stars 193 forks source link

Optimizations for AbstractExcerpt.appendLong0() and .appendDouble0() #28

Closed abissell closed 11 years ago

abissell commented 11 years ago

I imagine most clients are using writeLong() and writeDouble() most of the time anyway, but I was able to make these other appending functions run a little faster by eliminating the need for an Arrays.binarySearch() on the powers of 10. It's about a ~30% improvement over the existing code.

It appeared to me that the AbstractExcerpt is intended to be used thread locally. If that's not the case, then the buffers which I added to the class would need to be put in a ThreadLocal (a quick single-threaded benchmark indicated this wasn't a crippling performance hit or anything).

All the tests currently pass. I added NewVsOldNumberAppendTest to allow the existing algorithms to be compared against my proposed ones.

Of course, I'd always be interested to hear if the code is broken in some subtle way as well. :)

peter-lawrey commented 11 years ago

Thank you for the improvement. It is expect that if you need thread safety, this will be done externally via synchronized or a Lock. If you do this, everything should work.

abissell commented 11 years ago

Thanks for merging these in Peter, it's a point of pride to have contributed a bit of code to Chronicle. :)

peter-lawrey commented 11 years ago

It's a point of pride to have more contributors. Thank you.