So, can I ask, do you actually *have* a performance problem right now?

What the size of this problem (Things take 1 minute when you need them
in 20 seconds?)

On Jul 22, 12:18 am, Alan Kent <[email protected]> wrote:
> I was wondering what the fastest way (most highly performant) was to
> parse data structures serialized as an array of bytes.  In my case its
> like a network packet (a true array of bytes where I need to peel of 1,
> 2, 4, and 8 byte integers, or variable length ASCII (8-bit) strings, etc.)
>
> Note I am after the FASTEST way to do this in Java (and/or Scala).  Is
> it better to use the stream based classes, or is it better to do direct
> array accesses and do bit shift operations and masks with 0xff etc (to
> strip sign extension Java will do otherwise)?  I suspect the stream
> based approaches would be slower.  Sample code that sneaks in:
>
>      byte b1 = buf[i++];
>      byte b2 = buf[i++];
>      byte b3 = buf[i++];
>      byte b4 = buf[i++];
>      int n = (b1 << 24) | ((b2 & 0xff) << 16) | ((b3 & 0xff) << 8) | (b4
> & 0xff); // Must mask with 0xff or else sign extension will mess up the
> result. Java does not have unsigned bytes or ints!
>
> I was looking into array bounds checks, and what I found via Google
> indicated that hotspot leaves in array bounds checks as there was only a
> minor performance improvement found in practice.  This lead me to wonder
> if there is a faster way to do the code since I would be doing lots of
> array accesses, each with a bounds check.
>
> Just curious!
>
> Thanks!
> Alan

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to