Closed Bug 196557 Opened 22 years ago Closed 21 years ago

[FIX]Lots of empty <style> tags slow rendering down [100% processor utilization]

Categories

(Core :: CSS Parsing and Computation, defect, P1)

defect

Tracking

()

VERIFIED FIXED
mozilla1.5alpha

People

(Reporter: waltergarcia, Assigned: bzbarsky)

References

()

Details

(Keywords: perf, testcase)

Attachments

(3 files, 2 obsolete files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030308
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030308

The right column at http://theburritosband.vivelared.com/index.php, wich uses
Javascript to scroll some links makes Mozilla1.3 to use 100% of cpu and then hangs.

I had the same problem with Phoenix0.5 (1.3) but it only lasted a seconds, after
that the cpu utilization used to go down to normal cpu use.

Reproducible: Always

Steps to Reproduce:
1. Visit http://theburritosband.vivelared.com/index.php
2. Watch your CPU utilization
3.




I have tested it on Linux and Windows2K.
Flags: blocking1.3?
wfm with win2k build 20030303.. (no hang)

why should this be a blocker ? -> critical
Severity: blocker → critical
Severity: critical → normal
Flags: blocking1.3? → blocking1.3-
I see the problem with Mozilla trunk binary 2003022808 on WinNT.
My CPU is 100% for almost a minute while the page loads. The 
browser doesn't hang: one can interact with it, but only slowly.

This does not appear to be a JavaScript problem. The site is 
very light on JavaScript: I see hardly any. The marquees are
not created via JavaScript, but by <marquee> elements in HTML:

<MARQUEE behavior= "scroll" align= "center" direction= "up" height="120"
scrollamount= "2" scrolldelay= "90" onmouseover='this.stop()'
onmouseout='this.start()'>

<MARQUEE behavior= "scroll" align= "center" direction= "up" height="420"
scrollamount= "2" scrolldelay= "20" onmouseover='this.stop()'
onmouseout='this.start()'>

I did some reductions via Composer and found that removing some of
the content to the left of the marquees, or above them, resulted in
a much faster load time. So perhaps it's a reflow issue of some sort?

Reassigning to Layout for further analysis -
Assignee: rogerl → other
Status: UNCONFIRMED → NEW
Component: JavaScript Engine → Layout
Ever confirmed: true
Keywords: perf
QA Contact: pschwartau → ian
Priority: -- → P2
Target Milestone: --- → Future
the page contains lots of <STYLE="text-decoration: none">
removing them solves the problem

-> parser
Assignee: other → harishd
Component: Layout → Parser
QA Contact: ian → dsirnapalli
Summary: Javascript: 100% processor utilization, and then hangs → lots of <STYLE="text-decoration: none"> slows rendering down [100% processor utilization]
What does this have to do with parser?

You should try profiling the page before making decisions like that; at a guess,
what's going on here is that we add lots of style sheets (one per <style>
element) and each time we add a sheet we have to reresolve style all over.

Perhaps we could pass along some boolean in StyleSheetAdded saying whether the
sheet actually has any rules?  Or the presshell could do that check before
blowing away style data...
Assignee: harishd → dbaron
Component: Parser → Style System
QA Contact: dsirnapalli → ian
Attached patch possible patch, untested (obsolete) (deleted) — Splinter Review
Priority: P2 → --
Target Milestone: Future → ---
Attached file testcase (deleted) —
note: there are lots of open <style=> and <font> tags. Removing some of
them solves the problem
Summary: lots of <STYLE="text-decoration: none"> slows rendering down [100% processor utilization] → Lots of open tags (<font>, <style="text-decoration: none">) slows rendering down [100% processor utilization]
Attached file jprof profile (deleted) —
Total hit count: 1180

Of these 1034 happen under PresShell::ReconstructStyleData(int).  1065 hits
happen under ReResolveStyleContext; the top of the flat profile is:

Total hit count: 1180
Count %Total  Function Name
 82   6.9     SelectorMatches(RuleProcessorData &, nsCSSSelector *, int,
nsIAtom *, signed char)
 55   4.7     FrameManager::ReResolveStyleContext(nsIPresContext *, nsIFrame *,
nsIContent *, int, nsIAtom *, nsStyleChangeList &, nsChangeHint, nsChangeHint
&)
 43   3.6     RuleHash::EnumerateAllRules(int, nsIAtom *, nsIAtom *,
nsVoidArray &, void (*)(nsICSSStyleRule *, void *), void *)
 34   2.9     RuleProcessorData::RuleProcessorData(nsIPresContext *, nsIContent
*, nsRuleWalker *, nsCompatibility *)
 33   2.8     PL_DHashTableOperate
 26   2.2     nsCOMPtr_base::begin_assignment(void)
 26   2.2     SearchTable
 22   1.9     nsCOMPtr_base::~nsCOMPtr_base(void)
 21   1.8     ContentEnumFunc(nsICSSStyleRule *, void *)

Pretty much what you'd expect given the amount of time spent rebuilding the
style context tree....
Comment on attachment 119596 [details] [diff] [review]
possible patch, untested

OK, this patch speeds up this testcase by a factor of 12 or so according to
jprof (and "noticeably" according to wall clock).

Also fixes a bug where we could incorrectly leave rulenodes in the tree when a
style sheet got disabled...
Attachment #119596 - Flags: superreview?(dbaron)
Attachment #119596 - Flags: review?(dbaron)
Comment on attachment 119596 [details] [diff] [review]
possible patch, untested

The other option, of course, is to pass along in the notification itself
whether the sheet contains any rules....
.
Assignee: dbaron → bzbarsky
OS: Windows 2000 → All
Priority: -- → P1
Hardware: PC → All
Summary: Lots of open tags (<font>, <style="text-decoration: none">) slows rendering down [100% processor utilization] → [FIX]Lots of empty <style> tags slow rendering down [100% processor utilization]
Target Milestone: --- → mozilla1.4beta
Great, can we get this into 1.4beta ?
Blocks: 203448
Keywords: testcase
I was actually thinking of relying on the rule tree GC (and perhaps tuning the
parameters) and getting rid of the rule tree rebuilding code here.

The explicit CSS stuff seems ugly -- how about a new method on nsIStyleSheet? 
(|HasRules|?)
Comment on attachment 119596 [details] [diff] [review]
possible patch, untested

The problem is not the ruletree rebuilding -- it's not rebuilt, in fact, since
sheets are being added, not removed.

The problem is the top-down reresolve of style on every single piece of content
in the document.

Yes, HasRules is probably a better idea; I'll do something like that once I get
back to working on Moz.
Attachment #119596 - Flags: superreview?(dbaron)
Attachment #119596 - Flags: review?(dbaron)
Target Milestone: mozilla1.4beta → mozilla1.5alpha
I was just mentioning the rule tree rebuilding because I didn't see any reason
to add more of it.
Oh, the second hunk.  I see.  Yeah, that's a good point.
Attachment #119596 - Attachment is obsolete: true
Attached patch More ambitious patch (obsolete) (deleted) — Splinter Review
Comment on attachment 126862 [details] [diff] [review]
More ambitious patch

David?	What do you think?
Attachment #126862 - Flags: superreview?(dbaron)
Attachment #126862 - Flags: review?(dbaron)
Comment on attachment 126862 [details] [diff] [review]
More ambitious patch


>+NS_IMETHODIMP_(PRBool)
>+CSSStyleSheetImpl::HasRules() const
>+{
>+  if (!mInner || !mInner->mOrderedRules) {
>+    return PR_FALSE;
>+  }

Why bother?  StyleRuleCount does the same thing.

>+
>+  PRInt32 count;
>+  StyleRuleCount(count);
>+  return count != 0;
>+}

>+NS_IMETHODIMP_(PRBool)
>+HTMLCSSStyleSheetImpl::HasRules() const
>+{
>+  return mFirstLineRule || mFirstLetterRule;
> }

This should unconditionally return true, because of inline style rules, and
because the firstline and firstletter rules are allocated as needed.

> NS_IMETHODIMP
> PresShell::StyleSheetAdded(nsIDocument *aDocument,

>+
>+  if (!applicable) {
>+    return NS_OK;
>   }
> 
>-  return NS_OK;
>+  if (!aStyleSheet->HasRules()) {
>+    return NS_OK;
>+  }

how about:

if (!applicable || !aStyleSheet->HasRules) {
  return NS_OK;
}

(and the same for StyleSheetRemoved)

r+sr=dbaron
Attachment #126862 - Flags: superreview?(dbaron)
Attachment #126862 - Flags: superreview+
Attachment #126862 - Flags: review?(dbaron)
Attachment #126862 - Flags: review+
Attached patch Patch with those changes (deleted) — Splinter Review
Attachment #126862 - Attachment is obsolete: true
Checked in.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
v
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: