Skip to content

Commit

Permalink
amend: reintroduce prefetching
Browse files Browse the repository at this point in the history
Summary:
Add back prefetch optimization with a manual prefetch before the loop over `samefile()`.

Previously I had built this into `base.status(wctx)`, but I decided I didn't like that since it incurs a "real" diff operation that otherwise might not be needed. If you are amending to a large commit, you shouldn't need to diff the commit's changes.

Reviewed By: zzl0

Differential Revision: D66302022

fbshipit-source-id: 7d83e89f29ae627243133ba2e3d1e0dbc00574e6
  • Loading branch information
muirdm authored and facebook-github-bot committed Nov 21, 2024
1 parent f39784f commit 8386509
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
14 changes: 11 additions & 3 deletions eden/scm/sapling/cmdutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -3919,10 +3919,18 @@ def _amend(ui, repo, wctx, old, extra, opts, matcher):
# deleted), old X must be preserved.
with perftrace.trace("Prune files reverted by amend"):
statusmanifest = wctx.buildstatusmanifest(status)

if "remotefilelog" in repo.requirements:
# Prefetch files in `base` to avoid serial lookups.
fileids = base.manifest().walkfiles(
matchmod.exact("", "", status.modified + status.added)
)
repo.fileslog.filestore.prefetch(fileids)
repo.fileslog.metadatastore.prefetch(fileids, length=1)

for f in sorted(filestoamend):
if (
not samefile(f, wctx, base, m1=statusmanifest)
or f in status.deleted
if f in status.deleted or not samefile(
f, wctx, base, m1=statusmanifest
):
files.add(f)
else:
Expand Down
8 changes: 7 additions & 1 deletion eden/scm/sapling/ext/histedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
extensions,
hg,
lock,
match as matchmod,
merge as mergemod,
mergeutil,
mutation,
Expand All @@ -262,7 +263,6 @@
from sapling.i18n import _
from sapling.pycompat import range


# pyre-fixme[11]: Annotation `pickle` is not defined as a type.
pickle = util.pickle
release = lock.release
Expand Down Expand Up @@ -680,6 +680,12 @@ def collapse(repo, first, commitopts, skipprompt=False):
# Recompute copies (avoid recording a -> b -> a)
copied = copies.pathcopies(base, last)

if "remotefilelog" in repo.requirements:
# Prefetch files in `base` to avoid serial lookups.
fileids = base.manifest().walkfiles(matchmod.exact("", "", files))
repo.fileslog.filestore.prefetch(fileids)
repo.fileslog.metadatastore.prefetch(fileids, length=1)

# prune files which were reverted by the updates
files = [f for f in files if not cmdutil.samefile(f, last, base)]
# commit version of these files as defined by head
Expand Down
4 changes: 2 additions & 2 deletions eden/scm/tests/test-amend-file-fetches.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Make sure we minimize content fetches:
TRACE tree_fetches: attrs=["content"] keys=["@eaa109a0"]
TRACE file_fetches: attrs=["content"] keys=[".hgdirsync"]
TRACE tree_fetches: attrs=["content"] keys=["a_dir@4f20beec", "b_dir@79a5124d", "c_dir@bc250767"]
TRACE file_fetches: attrs=["content", "header", "aux"] keys=["b_dir/b", "c_dir/c"]
TRACE file_fetches: attrs=["history"] length=Some(1) keys=["b_dir/b", "c_dir/c"]
TRACE file_fetches: attrs=["content", "header"] keys=["b_dir/b"]
TRACE file_fetches: attrs=["content", "header"] keys=["c_dir/c"]
TRACE file_fetches: attrs=["content"] keys=[".hgdirsync"] (?)
TRACE file_fetches: attrs=["content", "header"] keys=[".hgdirsync"]
TRACE file_fetches: attrs=["history"] length=Some(1) keys=["b_dir/b"]
TRACE file_fetches: attrs=["history"] length=Some(1) keys=["c_dir/c"]

0 comments on commit 8386509

Please sign in to comment.