Closed Bug 42426 Opened 24 years ago Closed 24 years ago

nsPersistentProperties::Load() is too slow.

Categories

(Core :: XPCOM, defect, P3)

defect

Tracking

()

VERIFIED INVALID

People

(Reporter: beard, Assigned: scc)

References

Details

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);
      }
I tried rewriting the original algoritm, using a more sensible buffering 
strategy, but had difficulty getting the same results.
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
Closed: 24 years ago
Resolution: --- → INVALID
marking Verified per scc comment.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.