incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: faster ByteBuffer comparison
Date Sat, 02 Jul 2011 15:14:48 GMT
Quoting Yang <>:

I'd guess that getLong() is not faster because get() probably already benefits
from processor cache etc.

There are two concrete subclasses of ByteBuffer that implement get() -
HeapByteBuffer and DirectByteBuffer (for mapped memory).

It might be possible to optimise the comparison a little for the case where two
HeapByteBuffers are being compared - you could create a subclass with a
compareUnsigned method that directly accesses the byte[] in ByteBuffer, rather
than calling get().

However, you'd need to check how often this case occurs, and then benchmark
whether it really is any faster - Hotspot may optimise the current code well
enough that it makes little difference.

Optimising DirectByteBuffer comparisons, or a mixture of HeapByteBuffer and
DirectByteBuffer, looks unpromising, as DirectByteBuffer uses non-public
classes like sun.misc.Unsafe.

> I can see from profiling that a lot of the time in both reading and writing
> are spend on ByteBuffer compare on the column names (for long rows with many
> columns)
> I looked at the ByteBufferUtil.unsignedCompareByteBuffer() , it's basically
> the same structure as standard JVM
> looping over each byte doing a ByteBuffer.get()
> is there a faster (probably hardware-based) compare ? I tried doing 8 bytes
> at a time by doing getLong() and it actually seems slower
> thanks
> Yang

This message was sent using IMP, the Internet Messaging Program.

This email and any attachments to it may be confidential and are
intended solely for the use of the individual to whom it is addressed.
If you are not the intended recipient of this email, you must neither
take any action based upon its contents, nor copy or show it to anyone.
Please contact the sender if you believe you have received this email in
error. QinetiQ may monitor email traffic data and also the content of
email for the purposes of security. QinetiQ Limited (Registered in
England & Wales: Company Number: 3796233) Registered office: Cody Technology 
Park, Ively Road, Farnborough, Hampshire, GU14 0LX

View raw message