Re: [JGIT PATCH 03/15] Add IntList as a more efficient representation of List<Integer>
- From
Shawn O. Pearce <spearce@spearce.org>
- Date
- Dec 12, 2008, 15:41 UTC
- Message-ID
- <20081212154115.GO32487@spearce.org>
- In-Reply-To
- <bd6139dc0812120733o7c828532qbcd78c46a321fe6b@mail.gmail.com>
Sverre Rabbelier <srabbelier@gmail.com> wrote:
Show 7 quoted lines
> On Fri, Dec 12, 2008 at 16:15, Shawn O. Pearce <spearce@spearce.org> wrote: > > Hmm, yea, good point. But I don't care too much about the toString() > > in this case, its meant as a debugging aid and not something one > > would rely upon. Hence I didn't think it was worth testing for the > > empty list, writing the first entry, then doing a loop for [1,count). > > Fair enough :).
If you'd like to send a patch to change it, I'll apply it. But I don't think its worth my time to make this toString() more efficient.
Other areas of JGit I do try to micro-optimize, because they are right smack in the middle of the critical paths.
E.g. look at ObjectId.equals(byte[],int,byte[],int). I hand-unrolled the memcmp loop because the JIT on x86 does *soooo* much better when the code is spelled out:
public static boolean equals(final byte[] firstBuffer, final int fi,
final byte[] secondBuffer, final int si) {
return firstBuffer[fi] == secondBuffer[si]
&& firstBuffer[fi + 1] == secondBuffer[si + 1]
&& firstBuffer[fi + 2] == secondBuffer[si + 2]
&& firstBuffer[fi + 3] == secondBuffer[si + 3]
&& firstBuffer[fi + 4] == secondBuffer[si + 4]
&& firstBuffer[fi + 5] == secondBuffer[si + 5]
&& firstBuffer[fi + 6] == secondBuffer[si + 6]
&& firstBuffer[fi + 7] == secondBuffer[si + 7]
&& firstBuffer[fi + 8] == secondBuffer[si + 8]
&& firstBuffer[fi + 9] == secondBuffer[si + 9]
&& firstBuffer[fi + 10] == secondBuffer[si + 10]
&& firstBuffer[fi + 11] == secondBuffer[si + 11]
&& firstBuffer[fi + 12] == secondBuffer[si + 12]
&& firstBuffer[fi + 13] == secondBuffer[si + 13]
&& firstBuffer[fi + 14] == secondBuffer[si + 14]
&& firstBuffer[fi + 15] == secondBuffer[si + 15]
&& firstBuffer[fi + 16] == secondBuffer[si + 16]
&& firstBuffer[fi + 17] == secondBuffer[si + 17]
&& firstBuffer[fi + 18] == secondBuffer[si + 18]
&& firstBuffer[fi + 19] == secondBuffer[si + 19];
}This block is in the critical path for any tree diff code, in particular for a "git log -- a/" sort of operation. Its used to compare the SHA-1s from two different tree records to see if they differ. Not unrolling this was a huge penalty.
-- Shawn.