Closed Bug 77066 Opened 24 years ago Closed 24 years ago

CSS cascade uses O(N^2) array insertion

Categories

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

x86
Linux
defect

Tracking

()

VERIFIED FIXED

People

(Reporter: dbaron, Assigned: dbaron)

References

Details

(Keywords: perf)

Attachments

(2 files)

The CSS cascade uses O(N^2) array insertion. At least I sure think it does. Have a look at InsertRuleByWeight in nsCSSStyleSheet.cpp. InsertRuleByWeight shows up as 30/960 hits on a profile of opening new windows. I'm assigning this to myself, but if someone else wants to fix it, feel free to take it, since I probably won't get around to it for a while.
Actually, I changed my mind. Working on this right now...
Status: NEW → ASSIGNED
Priority: -- → P1
Oops, that leaks. New patch coming soon...
In my tree I just changed nsCOMPtr<nsISupportsArray> mRuleArray; to nsISupportsArray* mRuleArray; since it doesn't need to be a strong reference (which adds performance cost) since the hashtable already owns it.
Oh no, yet another nsHashKey subclass for me to whack in fixing bug 72722! Hey dbaron, any chance I could persuade you to use pldhash.h directly? S'ok either way (I'll fix up the patch in 72722 and land it for 0.9.1), just thought I'd ask. /be
It would be nice to have an nsIntKey :-). (I tried using nsVoidKey, but I couldn't get the compiler to accept the cast. I now realize a two-step cast might have worked, but it's annoying...)
I'll do an nsInt32Key in bug 72722 and switch this code to use it, if it's in by the time I fix 72722. /be
[s]r=attinasi
BTW: here is some informationj David sent me via email. Others may find this useful too. > > I started looking over your patch. Can you give me a brief overview of what > is going on? I think I understand it but... The old cascade algorithm got the weight of each rule (e.g., the 1-2-3 for p#foo[title="b"][lang|="en"]), found the first rule of that weight in a huge array sorted from highest weight to lowest (FindEndOfWeight should have been called FindStartOfWeight), and inserted the rule. The new approach creates a hashtable of arrays, one for each weight, and for each rule appends the rule to the appropriate array (creating the array if it doesn't already exist). It then appends these arrays into one big array (which requires reversing them) that is equivalent to the old one that was generated. > Also, What is the actual savings? Does this significantly change the amount > of time we spend opening a window? I think it saves about 2% of the time we spent opening a new window (I think it was 19 / 960 hits). (Opening a new window is an extreme case, since we cascade all the rules in all the stylesheets that apply to the main browser window!) -David
sr=waterson, although it makes me silently scream that nsISupportsArray is the de facto collection interface for the style system.
Fix checked in 2001-04-27 19:16 PDT.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
*** Bug 74906 has been marked as a duplicate of this bug. ***
verified as per developers comments
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: