# HG changeset patch # User Siddharth Agarwal # Date 1414922118 28800 # Node ID 05aea77371a3abfd16e3951e75f06528b7e75072 # Parent 11c8de73b48a5c9b8aa102f6d1c32ca852766d7c 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. diff --git a/hgsubversion/util.py b/hgsubversion/util.py --- 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.