Re: Optimization of java.io.DataInputStream

2013-11-12 Thread Alex Yursha
Well, I agree that the code is more readable when we use shift consistently, if you think it is worth some redundant bytes in a class file. On Tue, Nov 12, 2013 at 6:00 PM, Vitaly Davidovich wrote: > Roger, > > I think a simple comment is better than leaving head scratching code > behind, especi

Re: Optimization of java.io.DataInputStream

2013-11-12 Thread Vitaly Davidovich
So the locals can be called hi and lo, and it's very readable. Adding nop shifts would only be ok, IMHO, if it had zero cost all around (other than source being slightly larger). Sent from my phone On Nov 12, 2013 10:12 AM, "Alex Yursha" wrote: > Well, I agree that the code is more readable whe

Re: Optimization of java.io.DataInputStream

2013-11-12 Thread Vitaly Davidovich
Roger, I think a simple comment is better than leaving head scratching code behind, especially since it'll impact interpreter and byte code size. Sent from my phone On Nov 12, 2013 9:58 AM, "roger riggs" wrote: > Hi, > > At the source level the style makes it clear where the data is to be > ali

Re: Optimization of java.io.DataInputStream

2013-11-12 Thread roger riggs
Hi, At the source level the style makes it clear where the data is to be aligned. There many other places that use that style "<< 0" to indicate alignment of the data when assembling a whole from parts. It is assumed the compiler/runtime will omit unnecessary operations; the compiler does not

Re: Optimization of java.io.DataInputStream

2013-11-12 Thread Alex Yursha
I have no idea whether JIT compiler will eliminate these nop shifts, but as I said each such shift brings two redundant bytecode instructions for the virtual machine. It think this tiny optimization can benefit both interpreter and class file size. On Tue, Nov 12, 2013 at 5:45 PM, Vitaly Davidovi

Re: Optimization of java.io.DataInputStream

2013-11-12 Thread Vitaly Davidovich
Interesting - was this file codegen'd or something? Why are these nop shifts there? Anyway, I'd expect JIT does the right thing here and doesn't actually issue this instruction. Are you optimizing for interpreter or meta data size then? Sent from my phone On Nov 12, 2013 3:45 AM, "Alex Yursha"

Optimization of java.io.DataInputStream

2013-11-12 Thread Alex Yursha
The following methods in java.io.DataInputStream perform right shift to zero positions in their implementations: - short readShort() - int readUnsignedShort() - char readChar() - int readInt() - long readLong() - String readUTF(DataInput in) For example: public final short readShort() throws