speed up file merging
speed up file merging

Our file merging is dominated by very heavy comparison function. I've
spotted that previous binary-heap-based implementation was doing log_2
N comparisons twice per record. First to put record into heap and
second to remove it from heap.

Because we're doing 16-way merge (and we don't anticipate it being
much wider), I thought that simple insert-sort maintained sorted
vector would beat it. Particularly removal of least element does no
comparisons (it does memmove instead, but on short array that's very
cheap). And insertion does binary search to find position and memmove
to "create hole" for insertion.

Experimental results confirmed my finding. Particularly building
primary key index of 15E6 elements took 606 seconds instead of 665
seconds.

I have to admit that I've expected far bigger speedup but I now see
that I much understimated N log N factor of internal sorting of file
chunks, where smaller scale index sorting takes most of it's time.

Change-Id: I6da02231096d5138d19f9b0bb9e9d8b8175a2440
Reviewed-on: http://review.couchbase.org/29393
Tested-by: buildbot <80754af91bfb6d1073585b046fe0a474ce868509@couchbase.com>
Reviewed-by: Filipe David Borba Manana <e0fcd583df77ec6c08e6d1257619cc1216ddc994@gmail.com>
Tested-by: Filipe David Borba Manana <e0fcd583df77ec6c08e6d1257619cc1216ddc994@gmail.com>

couchbaselabs/couchstore,t3rm1n4l/couchstore,couchbaselabs/couchstore,t3rm1n4l/couchstore,abhinavdangeti/couchstore,abhinavdangeti/couchstore,jimwwalker/couchstore,abhinavdangeti/couchstore,t3rm1n4l/couchstore,vmx/couchstore,vmx/couchstore,jimwwalker/couchstore,jimwwalker/couchstore,couchbaselabs/couchstore,vmx/couchstore