Closed Bug 268932 Opened 20 years ago Closed 20 years ago

Reduce string copying/allocation from CAttributeToken::GetStringValue

Categories

(Core :: DOM: HTML Parser, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: bryner, Assigned: bryner)

Details

(Keywords: perf)

Attachments

(1 file)

CAttributeToken::GetStringValue calls AsString() on its nsScannerSubstring()
which does an unconditional copy of the buffer the first time it's called.  We
can optimize for the case where the string does not span multiple buffers and
return a nsDependentSubstring in that case.  On a test page I loaded
(home.netscape.com on Tp test), Quantify currently shows that malloc() is
responsible for 16.72% of time spent in nsParser::ResumeParse and descendents,
with 7971 calls.  With this patch, that drops to 9.375% with only 6057 calls.
Attached patch patchSplinter Review
This works; it's a bit hacky.  Another possibility is moving
nsTDependentSubstring::Rebind up to nsTSubstring and making it know how to free
any existing storage that's been allocated.
Attachment #165451 - Flags: superreview?(darin)
Attachment #165451 - Flags: review?(bzbarsky)
Comment on attachment 165451 [details] [diff] [review]
patch

this looks good to me.	ultimately, i would like to provide a method like
"AssignDependent" on nsSubstring, so that we can make it easier to implement
this kind of thing.

sr=me assuming boris is happy with the patch.
Attachment #165451 - Flags: superreview?(darin) → superreview+
Comment on attachment 165451 [details] [diff] [review]
patch

>Index: public/nsHTMLTokens.h

>@@ -359,13 +359,13 @@ public:
>   ~CAttributeToken() {}
>   virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode);
>   virtual PRInt32 GetTokenType(void);
>-  virtual const nsAString&     GetKey(void); // XXX {return mTextKey;}
>+  virtual const nsSubstring&     GetKey(void); // XXX {return mTextKey;}

Want to make this non-virtual while you're here?

>Index: src/nsScannerString.cpp

>+          mFlattenedRep.~nsString(); // in case we have a buffer currently
>+          new (&mutable_this->mFlattenedRep)
>+            nsDependentSubstring(mStart.mPosition, mEnd.mPosition);

So this makes the following assumptions:

1) The object layout of nsString and nsDependentSubstring is identical
   (including all data and vtables).
2) ~nsString does the right thing when called on the nsDependentSubstring (eg
   doesn't try to free the data).

These are somewhat nontrivial assumptions, since nsString and
nsDependentSubstring aren't even ancestors of each other; they're siblings
(both inheriting from nsSubstring).

Please document those clearly, and do file a followup bug to have a way to do
this that doesn't involve knowing that these classes are somehow "the same"...

r=bzbarsky with that.
Attachment #165451 - Flags: review?(bzbarsky) → review+
Summary: Reduce string copying/allocation from CAttriuteToken::GetStringValue → Reduce string copying/allocation from CAttributeToken::GetStringValue
checked in. follow-up bug is bug 269054.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
This seems to have retaken some of the Tp time (btek) lost during the last few
weeks. Great, thanks!
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: