* Monodoc/ecma-provider.cs: Reduce memory requirements when assembling
authorJonathan Pryor <jpryor@novell.com>
Fri, 11 Jun 2010 15:14:36 +0000 (15:14 -0000)
committerJonathan Pryor <jpryor@novell.com>
Fri, 11 Jun 2010 15:14:36 +0000 (15:14 -0000)
  ECMA documentation.  The problem was that we parse all the XML files
  in order to extract //summary and //remarks members, and then stored
  the XmlNodes for these members.  XmlNode keeps a ref to the creating
  XmlDocument, thus keeping the XmlNode around requires keeping the
  entire XmlDocument around; result: ~350+MB RAM is needed to assemble
  netdocs.zip (in ../../docs).  To fix, import the XmlNodes that we
  actually care about into an otherwise empty XmlDocument, so that we
  only save the nodes we need. Result: ~32MB RAM is needed.
  Fixes #602560.

svn path=/trunk/mcs/; revision=158835

mcs/tools/monodoc/ChangeLog
mcs/tools/monodoc/Monodoc/ecma-provider.cs

index 2ea79257c13db28843124b03565002f00ee8a9b2..d144be0d63a604894213a404295b9bbc5e5e5e2c 100644 (file)
@@ -1,3 +1,16 @@
+2010-06-11  Jonathan Pryor  <jpryor@novell.com>
+
+       * Monodoc/ecma-provider.cs: Reduce memory requirements when assembling
+         ECMA documentation.  The problem was that we parse all the XML files
+         in order to extract //summary and //remarks members, and then stored
+         the XmlNodes for these members.  XmlNode keeps a ref to the creating
+         XmlDocument, thus keeping the XmlNode around requires keeping the
+         entire XmlDocument around; result: ~350+MB RAM is needed to assemble
+         netdocs.zip (in ../../docs).  To fix, import the XmlNodes that we
+         actually care about into an otherwise empty XmlDocument, so that we 
+         only save the nodes we need. Result: ~32MB RAM is needed.
+         Fixes #602560.
+
 2010-04-25  Jonathan Pryor  <jpryor@novell.com>
 
        * Monodoc/ecma-provider.cs: Support the full set of possible operator
index 247553c421c359cb0e1540d200f49575340d9f45..d654a9a7f6bf3130101df907bde2f11f5a7aa7cb 100644 (file)
@@ -242,8 +242,8 @@ public class EcmaProvider : Provider {
                                                
                                                XmlNode ns_summary = nsSummaryFile.SelectSingleNode ("Namespace/Docs/summary");
                                                if (ns_summary != null && ns_summary.InnerText.Trim () != "To be added." && ns_summary.InnerText != "") {
-                                                       namespace_summaries [tn] = ns_summary;
-                                                       namespace_remarks [tn] = nsSummaryFile.SelectSingleNode ("Namespace/Docs/remarks");
+                                                       namespace_summaries [tn]  = detached.ImportNode (ns_summary, true);
+                                                       namespace_remarks [tn]    = detached.ImportNode (nsSummaryFile.SelectSingleNode ("Namespace/Docs/remarks"), true);
                                                }
                                                
                                        } else if (!namespace_summaries.ContainsKey (tn)) {
@@ -263,7 +263,7 @@ public class EcmaProvider : Provider {
 
        }
                
-       struct TypeInfo : IComparable {
+       class TypeInfo : IComparable {
                public string type_assembly;
                public string type_name;
                public string type_full;
@@ -398,15 +398,16 @@ public class EcmaProvider : Provider {
                }
        }
               
-       Hashtable class_summaries = new Hashtable ();
-       Hashtable namespace_summaries = new Hashtable ();
-       Hashtable namespace_remarks = new Hashtable ();
-       Hashtable namespace_realpath = new Hashtable ();
-       XmlDocument doc;
+       Hashtable/*<string, List<TypeInfo>>*/ class_summaries = new Hashtable ();
+       Hashtable/*<string, XmlNode>*/ namespace_summaries = new Hashtable ();
+       Hashtable/*<string, XmlNode>*/ namespace_remarks = new Hashtable ();
+       Hashtable/*<string, string -- path>*/ namespace_realpath = new Hashtable ();
+
+       XmlDocument detached = new XmlDocument ();
        
        void PopulateClass (Tree tree, string ns, Node ns_node, string file)
        {
-               doc = new XmlDocument ();
+               XmlDocument doc = new XmlDocument ();
                doc.Load (file);
                
                string name = EcmaDoc.GetClassName (doc);
@@ -417,7 +418,7 @@ public class EcmaProvider : Provider {
                Node class_node;
                string file_code = ns_node.tree.HelpSource.PackFile (file);
 
-               XmlNode class_summary = doc.SelectSingleNode ("/Type/Docs/summary");
+               XmlNode class_summary = detached.ImportNode (doc.SelectSingleNode ("/Type/Docs/summary"), true);
                ArrayList l = (ArrayList) class_summaries [ns];
                if (l == null){
                        l = new ArrayList ();
@@ -443,12 +444,12 @@ public class EcmaProvider : Provider {
                //
                class_node.CreateNode ("Members", "*");
 
-               PopulateMember (name, class_node, "Constructor", "Constructors");
-               PopulateMember (name, class_node, "Method", "Methods");
-               PopulateMember (name, class_node, "Property", "Properties");
-               PopulateMember (name, class_node, "Field", "Fields");
-               PopulateMember (name, class_node, "Event", "Events");
-               PopulateMember (name, class_node, "Operator", "Operators");
+               PopulateMember (doc, name, class_node, "Constructor", "Constructors");
+               PopulateMember (doc, name, class_node, "Method", "Methods");
+               PopulateMember (doc, name, class_node, "Property", "Properties");
+               PopulateMember (doc, name, class_node, "Field", "Fields");
+               PopulateMember (doc, name, class_node, "Event", "Events");
+               PopulateMember (doc, name, class_node, "Operator", "Operators");
        }
 
        class NodeIndex {
@@ -482,7 +483,7 @@ public class EcmaProvider : Provider {
        // Performs an XPath query on the document to extract the nodes for the various members
        // we also use some extra text to pluralize the caption
        //
-       void PopulateMember (string typename, Node node, string type, string caption)
+       void PopulateMember (XmlDocument doc, string typename, Node node, string type, string caption)
        {
                string select = type;
                if (select == "Operator") select = "Method";