Subject: lower RAM usage with xsltproc
To: None <tech-pkg@NetBSD.org>
From: Klaus Heinz <k.heinz.mai.fuenf@onlinehome.de>
List: tech-pkg
Date: 05/13/2005 00:25:48
--r5Pyd7+fXNt84Ff3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,

appended is a patch Hiroki Sato provided for textproc/libxslt (applies
to both current pkgsrc as well as pkgsrc-2005Q1).
This patch can dramatically reduce duplicate memory allocation for DTDs
if document() is used extensively in a stylesheet. The best example for
this is generating htdocs/autolayout.xml with and without the patch.

I would like to get some more feedback whether this works for other
stylesheets people use, so please apply this patch (save it as
pkgsrc/textproc/libxslt/patches/patch-ac, "make mps", then build) and
test your stylesheets with the new xsltproc binary.

ciao
     Klaus

--r5Pyd7+fXNt84Ff3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch-ac

--- libxslt/documents.c.orig	2004-08-17 07:49:56.000000000 +0900
+++ libxslt/documents.c	2005-05-07 12:27:33.000000000 +0900
@@ -255,6 +255,7 @@
 xsltLoadDocument(xsltTransformContextPtr ctxt, const xmlChar *URI) {
     xsltDocumentPtr ret;
     xmlDocPtr doc;
+    xmlDtdPtr intSubset, extSubset;
 
     if ((ctxt == NULL) || (URI == NULL))
 	return(NULL);
@@ -312,6 +313,24 @@
     if (ctxt->debugStatus == XSLT_DEBUG_NONE)
 	xmlXPathOrderDocElems(doc);
 
+    extSubset = doc->extSubset;
+    intSubset = doc->intSubset;
+
+    if (intSubset == extSubset)
+	extSubset = NULL;
+
+    if (extSubset != NULL) {
+        xmlUnlinkNode((xmlNodePtr) doc->extSubset);
+        doc->extSubset = NULL;
+        xmlFreeDtd(extSubset);
+    }
+
+    if (intSubset != NULL) {
+        xmlUnlinkNode((xmlNodePtr) doc->intSubset);
+        doc->intSubset = NULL;
+        xmlFreeDtd(intSubset);
+    }
+
     ret = xsltNewDocument(ctxt, doc);
     return(ret);
 }

--r5Pyd7+fXNt84Ff3--