git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4] git-p4: improve performance with large files

From
Sam Hocevar <sam@zoy.org>
Date
Mar 6, 2009, 10:13 UTC
Message-ID
<20090306101339.GB12880@zoy.org>
In-Reply-To
<7vfxhrt2by.fsf@gitster.siamese.dyndns.org>
On Fri, Mar 06, 2009, Junio C Hamano wrote:
> Sorry, but that's not a commit log message, so signing it off does not add
> much value to the patch.
   I'm sorry, for some reason git format-patch is eating my commit
messages (other commits appear just fine). As I'm doing this from a
Windows machine, I smell CR/LF issues in msysgit. Here is a clean
version:

git-p4: improve performance when importing huge files by reducing the number of string concatenations while constraining memory usage.

Signed-off-by: Sam Hocevar <sam@zoy.org>
---
 contrib/fast-import/git-p4 |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 3832f60..db0ea0a 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -984,11 +984,22 @@ class P4Sync(Command):
         while j < len(filedata):
             stat = filedata[j]
             j += 1
+            data = []
             text = ''
+            # Append data every 8192 chunks to 1) ensure decent performance
+            # by not making too many string concatenations and 2) avoid
+            # excessive memory usage by purging "data" often enough. p4
+            # sends 4k chunks, so we should not use more than 32 MiB of
+            # additional memory while rebuilding the file data.
             while j < len(filedata) and filedata[j]['code'] in ('text', 'unicod
e', 'binary'):
-                text += filedata[j]['data']
+                data.append(filedata[j]['data'])
                 del filedata[j]['data']
+                if len(data) > 8192:
+                    text += ''.join(data)
+                    data = []
                 j += 1
+            text += ''.join(data)
+            data = None

             if not stat.has_key('depotFile'):
                 sys.stderr.write("p4 print fails with: %s\n" % repr(stat))
-- 
Sam.
Previous: Junio C HamanoNext: Sam Hocevar
Message 9 of 10 in “git-p4: improve performance with large files”
  1. git-p4: improve performance with large filesSam Hocevar, Mar 4, 2009
  2. thestar@fussycoder.id.auMar 4, 2009
  3. Sam HocevarMar 5, 2009
  4. thestar@fussycoder.id.auMar 6, 2009
  5. Junio C HamanoMar 6, 2009
  6. Han-Wen NienhuysMar 6, 2009
  7. Sam HocevarMar 6, 2009
  8. Junio C HamanoMar 6, 2009
  9. git-p4: improve performance with large filesSam Hocevar, Mar 6, 2009
  10. git-p4: improve performance when importing huge files by reducing the number of string concatenations while constraining memory usage.Sam Hocevar, Mar 7, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.