Thread (4 messages) 4 messages, 2 authors, 2016-06-15

Re: [JGIT PATCH 03/15] Add IntList as a more efficient representation of List<Integer>

From: Shawn O. Pearce <hidden>
Date: 2016-06-15 22:45:46

Sverre Rabbelier [off-list ref] wrote:
On Fri, Dec 12, 2008 at 16:15, Shawn O. Pearce [off-list ref] wrote:
quoted
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help