[PATCH 5 of 5] revlog: use existing file handle when reading during _addrevision
Gregory Szorc
gregory.szorc at gmail.com
Sun Sep 27 22:32:14 CDT 2015
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1443395298 25200
# Sun Sep 27 16:08:18 2015 -0700
# Node ID a3168b60235b22320db09579e85408f4f46a3d7b
# Parent d96325c529d1b114ded988b22114d28f219d6fdd
revlog: use existing file handle when reading during _addrevision
_addrevision() may need to read from revlogs as part of computing
deltas. Previously, we would flush existing file handles and open
a new, short-lived file handle to perform the reading.
If we have an existing file handle, it seems logical to reuse it
for reading instead of opening a new file handle. This patch
makes that the new behavior.
After this patch, revlog files are only reopened when adding
revisions if the revlog is switched from inline to non-inline.
On Linux when unbundling a bundle of the mozilla-central repo, this
patch has the following impact on system call counts:
Call Before After Delta
write 827,639 673,390 -154,249
open 700,103 684,089 -16,014
read 74,489 74,489 0
fstat 493,924 461,896 -32,028
close 249,131 233,117 -16,014
stat 242,001 242,001 0
lstat 18,676 18,676 0
lseek 20,268 20,268 0
ioctl 14,652 13,173 -1,479
TOTAL 3,180,758 2,930,679 -250,079
It's worth noting that many of the open() calls fail due to missing
files. That's why there are many more open() calls than close().
Despite the significant system call reduction, this change does not
seem to have a significant performance impact on Linux.
On Windows 10 (not a VM, on a SSD), this patch appears to reduce
unbundle time for mozilla-central from ~960s to ~920s. This isn't
as significant as I was hoping. But a decrease it is nonetheless.
Still, Windows unbundle performance is still >2x slower than Linux.
Despite the lack of significant gains, fewer system calls is fewer
system calls. If nothing else, this will narrow the focus of potential
areas to optimize in the future.
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1288,12 +1288,8 @@ class revlog(object):
btext = [text]
def buildtext():
if btext[0] is not None:
return btext[0]
- # flush any pending writes here so we can read it in revision
- if dfh:
- dfh.flush()
- ifh.flush()
baserev = cachedelta[0]
delta = cachedelta[1]
# special case deltas which replace entire base; no need to decode
# base revision. this neatly avoids censored bases, which throw when
@@ -1302,9 +1298,13 @@ class revlog(object):
if delta[:hlen] == mdiff.replacediffheader(self.rawsize(baserev),
len(delta) - hlen):
btext[0] = delta[hlen:]
else:
- basetext = self.revision(self.node(baserev))
+ if self._inline:
+ fh = ifh
+ else:
+ fh = dfh
+ basetext = self.revision(self.node(baserev), _df=fh)
btext[0] = mdiff.patch(basetext, delta)
try:
self.checkhash(btext[0], p1, p2, node)
if flags & REVIDX_ISCENSORED:
@@ -1326,9 +1326,13 @@ class revlog(object):
# full content in one patch, so delta works everywhere
header = mdiff.replacediffheader(self.rawsize(rev), len(t))
delta = header + t
else:
- ptext = self.revision(self.node(rev))
+ if self._inline:
+ fh = ifh
+ else:
+ fh = dfh
+ ptext = self.revision(self.node(rev), _df=fh)
delta = mdiff.textdiff(ptext, t)
data = self.compress(delta)
l = len(data[1]) + len(data[0])
if basecache[0] == rev:
More information about the Mercurial-devel
mailing list