Closed
Bug 99797
Opened 24 years ago
Closed 24 years ago
style.color parses too much (DHTML optimisation)
Categories
(Core :: DOM: CSS Object Model, defect)
Tracking
()
RESOLVED
FIXED
mozilla0.9.5
People
(Reporter: ian, Assigned: bzbarsky)
References
Details
(Keywords: perf, Whiteboard: [Hixie-P2])
Attachments
(6 files, 3 obsolete files)
|
614 bytes,
text/html
|
Details | |
|
675 bytes,
text/html
|
Details | |
|
20.36 KB,
patch
|
Details | Diff | Splinter Review | |
|
20.61 KB,
patch
|
attinasi
:
review+
jst
:
superreview+
|
Details | Diff | Splinter Review |
|
513.81 KB,
text/html
|
Details | |
|
318.50 KB,
text/html
|
Details |
To set a property at the moment, we parse way more than we need to (just follow
the code path from |style.border| -- we first create a full declaration, then parse
it, looking for which property it is, whether it is !important, etc). We should
just expose a wrapper for CSSParserImpl::ParseProperty, and call that directly.
| Assignee | ||
Updated•24 years ago
|
OS: Windows 2000 → All
Comment 1•24 years ago
|
||
Reassigning to pierre to work on an API to the style system that lets us do
this. Pierre, if this is not your problem, please reassign.
Assignee: jst → pierre
| Assignee | ||
Comment 3•24 years ago
|
||
| Assignee | ||
Comment 4•24 years ago
|
||
| Assignee | ||
Comment 5•24 years ago
|
||
| Assignee | ||
Comment 6•24 years ago
|
||
On that first testcase (setting style.top 5000 times) my opt build went from
Avg: 3.268
Stddev: 0.040
to
Avg: 3.080
Stddev: 0.042
an speedup of 5.8% or so.
Reviews?
Comment 7•24 years ago
|
||
Holy &^*!, CSSLoaderImpl::RecycleParser() screws up the refcount on the parsers
that it recycles, wanna fix that while you're at it, if you do you could make
your nsICSSParser*'s nsCOMPtr<nsICSSParser>'s?
| Assignee | ||
Comment 8•24 years ago
|
||
Sure thing. That behavior _did_ strike me as very odd... :)
| Assignee | ||
Comment 9•24 years ago
|
||
| Assignee | ||
Updated•24 years ago
|
Attachment #49830 -
Attachment is obsolete: true
Comment 10•24 years ago
|
||
I would suggest loosing the redundancy in code that does things like this:
+ result = mContent->GetDocument(*getter_AddRefs(doc));
if (NS_SUCCEEDED(result) && (nsnull != doc)) {
- doc->GetBaseURL(baseURI);
+ doc->GetBaseURL(*getter_AddRefs(baseURI));
There's no need to check for "NS_SUCCEEDED(result)" and "nsnull != doc" (which
should sumply be "doc", simply checking for "doc" is all you need. There's a
bunch of raw QueryyInterface() calls that were converted into
do_QueryInterface(ptr, &result), loose the result where it's not needed,
checking for success by checking that the nsCOMPtr is non-null is enough.
- In CSSParserImpl::ParseProperty():
+ nsString* str = new nsString(aPropValue);
+ if (nsnull == str) {
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
why not simply if (!str)?
- In nsDOMCSSDeclaration.cpp:
return aDecl->RemoveProperty(aPropName,
nsDependentString(&nullChar, PRUint32(0)));
is faster and less code than using a nsAutoString for the empty string.
- In nsDOMCSSDeclaration.h, use const nsAReadableString& and not const
nsAString& for consistency, they are the same thing.
Other than that the changes look good, but please attach a new patch and I'll
have one more look.
| Assignee | ||
Comment 11•24 years ago
|
||
> return aDecl->RemoveProperty(aPropName,
nsDependentString(&nullChar, PRUint32(0)));
>
> is faster and less code than using a nsAutoString for the empty string.
Unfortunately, RemoveProperty wants a writable string that it then proceeds to
write to.... so it seems to make sense to pass in an nsAutoString...
Attaching patch that addresses the other comments
| Assignee | ||
Comment 12•24 years ago
|
||
| Assignee | ||
Updated•24 years ago
|
Attachment #49936 -
Attachment is obsolete: true
Comment 13•24 years ago
|
||
+ if (!aValue.Length()) {
+ // If the new value of the property is an empty string we remove the
Please use IsEmpty() instead of fetching the length, which could (if we do lazy
length computation) become costly. It's also more expressive, as jag points out
(cc'ing him).
/be
| Assignee | ||
Comment 14•24 years ago
|
||
Oops. That's what I get for copying and pasting code. Length() usage fixed,
attaching new patch. Filed bug 100649 on similar usages in other parts of
related code.
| Assignee | ||
Comment 15•24 years ago
|
||
Comment 16•24 years ago
|
||
- In CSSParserImpl::ParseProperty(), no need for " = null" for nsCOMPtr's:
+ nsCOMPtr<nsIUnicharInputStream> input = nsnull;
- In DOMCSSDeclarationImpl::ParsePropertyValue():
+ result = htmlContainer->GetCSSLoader(*getter_AddRefs(cssLoader));
+ }
+ }
+ }
+ }
+ if (cssLoader) {
+ result = cssLoader->GetParserFor(nsnull, getter_AddRefs(cssParser));
+ }
+ else {
+ result = NS_NewCSSParser(getter_AddRefs(cssParser));
+ }
'result' from htmlContainer->GetCSSLoader() is never used, either check it and
return it, or remove it (I vote for remove it), same goes for the same (or very
similar) code in DOMCSSDeclarationImpl::ParseDeclaration().
With that, sr=jst
| Assignee | ||
Comment 17•24 years ago
|
||
OK. Attaching patch with that change.
An interesting question... The testcase that modifies the style rule (instead
of modifying the style attribute) runs about twice as fast as the other one. I
wonder what the reasons for that are...
| Assignee | ||
Comment 18•24 years ago
|
||
Updated•24 years ago
|
Attachment #50037 -
Flags: superreview+
| Assignee | ||
Updated•24 years ago
|
Attachment #49990 -
Attachment is obsolete: true
| Assignee | ||
Comment 19•24 years ago
|
||
Interesting... I did two profiles (mozilla on each of the testcases). Neither
has an obvious processor hogging function in it. The only major difference that
I can see that would account for the factor of 2 speed difference is:
Total hit count: 3104
Total hit count: 1597
| Assignee | ||
Comment 20•24 years ago
|
||
| Assignee | ||
Comment 21•24 years ago
|
||
Comment 22•24 years ago
|
||
Comment on attachment 50037 [details] [diff] [review]
Patch addressing last set of jst's comments
r=attinasi - but, I think you should get review from the style module owner or a peer: dbaron or pierre or glazman I think would be good.
Attachment #50037 -
Flags: review+
attachment 50037 [details] [diff] [review] seems fine to me, although I have a few general concerns
(perhaps they could be addressed in a later patch, or maybe you prefer to
address them now):
* nsICSSParser::ParseProperty is intended to be used externally -- so does the
aHint parameter make sense? It looks like it's never used. Would it ever be?
(Could it replace CaptureChange? Is CaptureChange used here?)
* You've now duplicated code so that code that used to be almost identical in
two places is now duplicated in 4 places. Any chance of condensing this?
| Assignee | ||
Comment 24•24 years ago
|
||
> so does the aHint parameter make sense? It looks like it's never used.
Sure it is. It's passed to the document in the StyleRuleChanged() or
AttributeChanged() calls
> You've now duplicated code so that code that used to be almost identical in
> two places is now duplicated in 4 places. Any chance of condensing this?
Hmm. I suppose I could add some helper functions to get the CSS parser to those
classes (collapsing the number of copies of code back to 2). I think I'd prefer
to do it as part of my patch to bug 95336 which will slightly rework the
parser-getting mechanism....
Comment 25•24 years ago
|
||
Agreed: bug 95336 is the place to do the cleanup and make sure we are not missing
anything before re-using the parser.
| Assignee | ||
Comment 26•24 years ago
|
||
Marc says he's happy with David and Pierre's comments. Checked in on trunk.
Marking fixed.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•