summaryrefslogtreecommitdiff
path: root/merge-ort.c
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2021-06-22 08:04:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-06-28 14:58:25 (GMT)
commit2bff554b23e8d5c17f4e6827358bb51811fc7137 (patch)
treec5b500f1ac0a768226c25d641e60f71dc3f41993 /merge-ort.c
parent1aedd03afb1592be9e4fbacdc614f45a99a865ea (diff)
downloadgit-2bff554b23e8d5c17f4e6827358bb51811fc7137.zip
git-2bff554b23e8d5c17f4e6827358bb51811fc7137.tar.gz
git-2bff554b23e8d5c17f4e6827358bb51811fc7137.tar.bz2
merge-ort: add prefetching for content merges
Commit 7fbbcb21b1 ("diff: batch fetching of missing blobs", 2019-04-05) introduced batching of fetching missing blobs, so that the diff machinery would have one fetch subprocess grab N blobs instead of N processes each grabbing 1. However, the diff machinery is not the only thing in a merge that needs to work on blobs. The 3-way content merges need them as well. Rather than download all the blobs 1 at a time, prefetch all the blobs needed for regular content merges. This does not cover all possible paths in merge-ort that might need to download blobs. Others include: - The blob_unchanged() calls to avoid modify/delete conflicts (when blob renormalization results in an "unchanged" file) - Preliminary content merges needed for rename/add and rename/rename(2to1) style conflicts. (Both of these types of conflicts can result in nested conflict markers from the need to do two levels of content merging; the first happens before our new prefetch_for_content_merges() function.) The first of these wouldn't be an extreme amount of work to support, and even the second could be theoretically supported in batching, but all of these cases seem unusual to me, and this is a minor performance optimization anyway; in the worst case we only get some of the fetches batched and have a few additional one-off fetches. So for now, just handle the regular 3-way content merges in our prefetching. For the testcase from the previous commit, the number of downloaded objects remains at 63, but this drops the number of fetches needed from 32 down to 20, a sizeable reduction. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge-ort.c')
-rw-r--r--merge-ort.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/merge-ort.c b/merge-ort.c
index b954f71..ccf85b7 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -29,6 +29,7 @@
#include "entry.h"
#include "ll-merge.h"
#include "object-store.h"
+#include "promisor-remote.h"
#include "revision.h"
#include "strmap.h"
#include "submodule.h"
@@ -3460,6 +3461,54 @@ static void process_entry(struct merge_options *opt,
record_entry_for_tree(dir_metadata, path, &ci->merged);
}
+static void prefetch_for_content_merges(struct merge_options *opt,
+ struct string_list *plist)
+{
+ struct string_list_item *e;
+ struct oid_array to_fetch = OID_ARRAY_INIT;
+
+ if (opt->repo != the_repository || !has_promisor_remote())
+ return;
+
+ for (e = &plist->items[plist->nr-1]; e >= plist->items; --e) {
+ /* char *path = e->string; */
+ struct conflict_info *ci = e->util;
+ int i;
+
+ /* Ignore clean entries */
+ if (ci->merged.clean)
+ continue;
+
+ /* Ignore entries that don't need a content merge */
+ if (ci->match_mask || ci->filemask < 6 ||
+ !S_ISREG(ci->stages[1].mode) ||
+ !S_ISREG(ci->stages[2].mode) ||
+ oideq(&ci->stages[1].oid, &ci->stages[2].oid))
+ continue;
+
+ /* Also don't need content merge if base matches either side */
+ if (ci->filemask == 7 &&
+ S_ISREG(ci->stages[0].mode) &&
+ (oideq(&ci->stages[0].oid, &ci->stages[1].oid) ||
+ oideq(&ci->stages[0].oid, &ci->stages[2].oid)))
+ continue;
+
+ for (i = 0; i < 3; i++) {
+ unsigned side_mask = (1 << i);
+ struct version_info *vi = &ci->stages[i];
+
+ if ((ci->filemask & side_mask) &&
+ S_ISREG(vi->mode) &&
+ oid_object_info_extended(opt->repo, &vi->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
+ oid_array_append(&to_fetch, &vi->oid);
+ }
+ }
+
+ promisor_remote_get_direct(opt->repo, to_fetch.oid, to_fetch.nr);
+ oid_array_clear(&to_fetch);
+}
+
static void process_entries(struct merge_options *opt,
struct object_id *result_oid)
{
@@ -3506,6 +3555,7 @@ static void process_entries(struct merge_options *opt,
* the way when it is time to process the file at the same path).
*/
trace2_region_enter("merge", "processing", opt->repo);
+ prefetch_for_content_merges(opt, &plist);
for (entry = &plist.items[plist.nr-1]; entry >= plist.items; --entry) {
char *path = entry->string;
/*