Bug 510652 - Port Bug 477564 - Session restore hangs/not responding with high CPU on large form with many checkboxes; r+sr=neil
authorJens Hatlak <jh@junetz.de>
Wed, 19 Aug 2009 01:25:15 +0200
changeset 3328 140d79e50cc7a8494638eddd0ab97e3e4196958a
parent 3327 8c234c13c206c298db745b29e50c27932d5f1372
child 3329 465d5fd23b833b4f6a9eb848f98ac0a2cfe95809
push idunknown
push userunknown
push dateunknown
bugs510652, 477564
Bug 510652 - Port Bug 477564 - Session restore hangs/not responding with high CPU on large form with many checkboxes; r+sr=neil
suite/common/src/nsSessionStore.js
--- a/suite/common/src/nsSessionStore.js
+++ b/suite/common/src/nsSessionStore.js
@@ -1286,18 +1286,25 @@ SessionStoreService.prototype = {
   _collectFormDataForFrame: function sss_collectFormDataForFrame(aDocument) {
     let formNodes = aDocument.evaluate(XPathHelper.restorableFormNodes, aDocument,
                                        XPathHelper.resolveNS,
                                        Components.interfaces.nsIDOMXPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
     let node = formNodes.iterateNext();
     if (!node)
       return null;
 
+    const MAX_GENERATED_XPATHS = 100;
+    let generatedCount = 0;
+
     let data = {};
     do {
+      // Only generate a limited number of XPath expressions for perf reasons (cf. bug 477564)
+      if (!node.id && ++generatedCount > MAX_GENERATED_XPATHS)
+        continue;
+
       let id = node.id ? "#" + node.id : XPathHelper.generate(node);
       if (node instanceof Components.interfaces.nsIDOMHTMLInputElement) {
         if (node.type != "file")
           data[id] = node.type == "checkbox" || node.type == "radio" ? node.checked : node.value;
         else
           data[id] = { type: "file", value: node.value };
       }
       else if (node instanceof Components.interfaces.nsIDOMHTMLTextAreaElement)