Patchwork D5296: store: don't read the whole fncache in memory

login
register
mail settings
Submitter phabricator
Date Feb. 27, 2019, 2:05 p.m.
Message ID <34771dcf6beb84cc42d4db7b996e1a29@localhost.localdomain>
Download mbox | patch
Permalink /patch/38951/
State Not Applicable
Headers show

Comments

phabricator - Feb. 27, 2019, 2:05 p.m.
pulkit updated this revision to Diff 14255.
pulkit edited the summary of this revision.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5296?vs=12583&id=14255

REVISION DETAIL
  https://phab.mercurial-scm.org/D5296

AFFECTED FILES
  mercurial/store.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: indygreg, yuja, mjpieters, mercurial-devel

Patch

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -463,7 +463,30 @@ 
             # skip nonexistent file
             self.entries = set()
             return
-        self.entries = set(decodedir(fp.read()).splitlines())
+
+        self.entries = []
+        #import pdb; pdb.set_trace()
+        totalsize = self.vfs.stat('fncache').st_size
+        chunksize = (10 ** 6) # 10 Megabytes
+        chunk = b''
+        chunksize = min(totalsize, chunksize)
+        totalsize -= chunksize
+        while chunksize:
+            chunk += fp.read(chunksize)
+            try:
+                p = chunk.rindex(b'\n')
+                self.entries.extend(decodedir(chunk[:p + 1]).splitlines())
+                chunk = chunk[p + 1:]
+            except ValueError:
+                # substring '\n' not found
+                pass
+            chunksize = min(totalsize, chunksize)
+            totalsize -= chunksize
+
+        if chunk:
+            self.entries.extend(decodedir(chunk[:p + 1]).splitlines())
+
+        self.entries = set(self.entries)
         self._checkentries(fp)
         fp.close()