Extremely fast 8 bytes to double in Java - For HFT application

374 Views Asked by At

our HFT trading application is developed in Java. We need to convert 8 bytes to a double number but the conversion has to be extremely fast. Remember our latency is under 15 micro second, so conventional java approaches will probably not work for us. Any suggestion would be helpful. Thanks in advance

[edit]

We have already worked on few approaches like byetebuffer, nio classes, twiddling approach (using shifting) etc. However, I would like to re-iterate the need to have each operation as fast as possible. Using these forms of conversions are expensive (even though they may seem faster as a standalone) & we end up introducing latency into the application. I am seeking out-of-the-box ideas (& not limited to the APIs provided by Java) which any one may have had experience on using bytes in different formats (int, double, float, etc). A thought in that direction is probably caching the double value and compare with the bytes received hence eliminating the need to convert.

1

There are 1 best solutions below

2
On

You'll likely want to be using java.nio for IO, in which case you can convert between ByteBuffer and DoubleBuffer to accomplish what you need. This will be much faster than bit twiddling with the logic for the conversion yourself.

It's as easy as:

ByteBuffer buffer.allocateDirect(<size>);
... add to the buffer ...
DoubleBuffer db = buffer.asDoubleBuffer();

voila.