changeset 1250:05aea77371a3

util: add a decorator to disable Python's garbage collector Python's GC can cause serious performance regressions if lots of small objects are created within a function. We've empirically found that that happens while loading the revmap.
author Siddharth Agarwal <sid0@fb.com>
date Sun, 02 Nov 2014 01:55:18 -0800
parents 11c8de73b48a
children 46cec117dda2
files hgsubversion/util.py
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/util.py
+++ b/hgsubversion/util.py
@@ -4,6 +4,7 @@ import re
 import os
 import urllib
 import json
+import gc
 
 from mercurial import cmdutil
 from mercurial import error
@@ -55,6 +56,18 @@ def filterdiff(diff, oldrev, newrev):
     diff = header_re.sub(r'Index: \1' + '\n' + ('=' * 67), diff)
     return diff
 
+def gcdisable(orig):
+    """decorator to disable GC for a function or method"""
+    def wrapper(*args, **kwargs):
+        enabled = gc.isenabled()
+        if enabled:
+            gc.disable()
+        try:
+            orig(*args, **kwargs)
+        finally:
+            if enabled:
+                gc.enable()
+    return wrapper
 
 def parentrev(ui, repo, meta, hashes):
     """Find the svn parent revision of the repo's dirstate.