Skip to content

Commit

Permalink
merge: prefetch merging file contents
Browse files Browse the repository at this point in the history
Summary: Batch prefetch contents of all files' contents involved in a merge. This might avoid serial content fetches in certain cases during rebase (with lots of files to be merged).

Reviewed By: quark-zju

Differential Revision: D65402133

fbshipit-source-id: 3f8a095ac89f73b71532daa51736304a37eec231
  • Loading branch information
muirdm authored and facebook-github-bot committed Nov 4, 2024
1 parent 8178392 commit 7221754
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 0 additions & 1 deletion eden/scm/sapling/ext/remotefilelog/remotefilectx.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from ..extlib.phabricator import graphql
from . import shallowutil


propertycache = util.propertycache
conduit = None
FASTLOG_TIMEOUT_IN_SECS = 0.5
Expand Down
2 changes: 1 addition & 1 deletion eden/scm/sapling/filemerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ def _makebackup(repo, ui, wctx, fcd, premerge):
# so we don't disturb the working directory.
relpath = back[len(repo.wvfs.base) + 1 :]
if premerge:
wctx[relpath].write(fcd.data(), fcd.flags())
wctx[relpath].write(fcd, fcd.flags())
return wctx[relpath]
else:
if premerge:
Expand Down
25 changes: 25 additions & 0 deletions eden/scm/sapling/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,31 @@ def applyupdates(repo, actions, wctx, mctx, overwrite, labels=None, ancestors=No
for m, l in actions.items():
l.sort()

# Prefetch content for files to be merged to avoid serial lookups.
merge_prefetch = []
for f, args, msg in (
actions[ACTION_CHANGED_DELETED]
+ actions[ACTION_DELETED_CHANGED]
+ actions[ACTION_MERGE]
):
f1, f2, fa, move, anc = args
if f1 is not None:
merge_prefetch.append(wctx[f1])
if f2 is not None:
merge_prefetch.append(mctx[f2])
actx = repo[anc]
if fa in actx:
merge_prefetch.append(actx[fa])
if merge_prefetch and hasattr(repo, "fileservice"):
repo.fileservice.prefetch(
[
(fc.path(), fc.filenode())
for fc in merge_prefetch
if fc.filenode() not in (None, nullid)
],
fetchhistory=False,
)

# These are m(erge) actions that aren't actually conflicts, such as remote copying a
# file. We don't want to expose them to merge drivers since merge drivers might get
# confused.
Expand Down
3 changes: 2 additions & 1 deletion eden/scm/tests/test-rebase-file-fetches.t
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Make sure we batch tree fetches well:
TRACE tree_fetches: attrs=["content"] keys=["a/b@105dfd91"]
TRACE file_fetches: attrs=["history"] length=Some(1) keys=["a/b/c2/file"]

FIXME Make sure we batch fetch content for files needing merge:
Make sure we batch fetch content for files needing merge:
$ newserver server3
$ drawdag <<EOS
> # C/bar = 2\n2\n3\n
Expand All @@ -60,6 +60,7 @@ FIXME Make sure we batch fetch content for files needing merge:
$ newclientrepo client3 test:server3
$ LOG=file_fetches=trace,tree_fetches=trace hg rebase -q -r $B -d $C
TRACE tree_fetches: attrs=["content"] keys=["@52df54bd", "@9e73d36f", "@c0749e87"]
TRACE file_fetches: attrs=["content", "header", "aux"] keys=["bar", "bar", "foo", "foo"]
TRACE file_fetches: attrs=["content", "header"] keys=["bar"]
TRACE file_fetches: attrs=["content", "header"] keys=["bar"]
TRACE file_fetches: attrs=["history"] length=Some(1) keys=["bar"]
Expand Down

0 comments on commit 7221754

Please sign in to comment.