[PATCH] bdiff.bdiff: release the GIL before doing expensive diff operations
Augie Fackler
raf at durin42.com
Fri Apr 20 15:33:02 CDT 2012
# HG changeset patch
# User Augie Fackler <raf at durin42.com>
# Date 1334938094 18000
# Branch stable
# Node ID b3e8717ff95fefdf352c051e373df16dd053f7eb
# Parent ee553e6cd8c445ff40ed15ca0ab1b9a3636a9ddc
bdiff.bdiff: release the GIL before doing expensive diff operations
This means that threaded webservers will have more of a chance of
doing something useful while the C extension is busy computing a
delta. Not doing this was causing problems for Google Code with a 25
meg text file that takes O(7 minutes) to deltify.
diff --git a/mercurial/bdiff.c b/mercurial/bdiff.c
--- a/mercurial/bdiff.c
+++ b/mercurial/bdiff.c
@@ -339,10 +339,12 @@
struct line *al, *bl;
struct hunk l, *h;
int an, bn, len = 0, la, lb, count;
+ PyThreadState *_save;
if (!PyArg_ParseTuple(args, "s#s#:bdiff", &sa, &la, &sb, &lb))
return NULL;
+ _save = PyEval_SaveThread();
an = splitlines(sa, la, &al);
bn = splitlines(sb, lb, &bl);
if (!al || !bl)
@@ -361,6 +363,8 @@
la = h->a2;
lb = h->b2;
}
+ PyEval_RestoreThread(_save);
+ _save = NULL;
result = PyBytes_FromStringAndSize(NULL, len);
@@ -385,6 +389,7 @@
}
nomem:
+ if (_save) PyEval_RestoreThread(_save);
free(al);
free(bl);
freehunks(l.next);
More information about the Mercurial-devel
mailing list