nsPersistentProperties::Load() is too slow.

VERIFIED INVALID

Status

()

Core
XPCOM
P3
normal
VERIFIED INVALID
18 years ago
18 years ago

People

(Reporter: Patrick C. Beard, Assigned: Scott Collins)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

18 years ago
With the recent string changes, I have a 256K .properties file that loads in 45 
seconds on my 400MHz Mac G3. This is unacceptable. The following patch fixes that 
(although perhaps not in the most ideal way):

Index: mozilla/xpcom/ds/nsPersistentProperties.cpp
===================================================================
RCS file: /cvsroot/mozilla/xpcom/ds/nsPersistentProperties.cpp,v
retrieving revision 1.8
diff -c -2 -r1.8 nsPersistentProperties.cpp
*** nsPersistentProperties.cpp	2000/05/26 20:59:04	1.8
--- nsPersistentProperties.cpp	2000/06/14 01:02:39
***************
*** 109,112 ****
--- 109,113 ----
      return NS_ERROR_FAILURE;
    }
+   nsAutoString key, value, oldValue;
    c = Read();
    while (1) {
***************
*** 120,125 ****
      }
      else {
!       nsAutoString key;
        while ((c >= 0) && (c != '=') && (c != ':')) {
          key.Append((PRUnichar) c);
          c = Read();
--- 121,128 ----
      }
      else {
!       key.Truncate(0);
        while ((c >= 0) && (c != '=') && (c != ':')) {
+         if (key.mCapacity == key.mLength)
+           key.SetCapacity(key.mCapacity * 2);
          key.Append((PRUnichar) c);
          c = Read();
***************
*** 131,135 ****
        key.Trim(trimThese, PR_FALSE, PR_TRUE);
        c = Read();
!       nsAutoString value;
        while ((c >= 0) && (c != '\r') && (c != '\n')) {
          if (c == '\\') {
--- 134,138 ----
        key.Trim(trimThese, PR_FALSE, PR_TRUE);
        c = Read();
!       value.Truncate(0);
        while ((c >= 0) && (c != '\r') && (c != '\n')) {
          if (c == '\\') {
***************
*** 139,150 ****
            }
            else {
              value.AppendWithConversion('\\');
            }
          }
          value.Append((PRUnichar) c);
          c = Read();
        }
        value.Trim(trimThese, PR_TRUE, PR_TRUE);
-       nsAutoString oldValue;
        mSubclass->SetStringProperty(key, value, oldValue);
      }
--- 142,156 ----
            }
            else {
+             if (value.mCapacity == value.mLength)
+               value.SetCapacity(value.mCapacity * 2);
              value.AppendWithConversion('\\');
            }
          }
+         if (value.mCapacity == value.mLength)
+           value.SetCapacity(value.mCapacity * 2);
          value.Append((PRUnichar) c);
          c = Read();
        }
        value.Trim(trimThese, PR_TRUE, PR_TRUE);
        mSubclass->SetStringProperty(key, value, oldValue);
      }
(Reporter)

Comment 1

18 years ago
I tried rewriting the original algoritm, using a more sensible buffering 
strategy, but had difficulty getting the same results.

Updated

18 years ago
Blocks: 42447
(Assignee)

Comment 2

18 years ago
string allocation policy has reverted to its original form, so I'm marking this 
bug as invalid (after all, it's not fixed, it's just restored to its original 
state).
Status: NEW → RESOLVED
Last Resolved: 18 years ago
Resolution: --- → INVALID

Comment 3

18 years ago
marking Verified per scc comment.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.