Closed Bug 523288 Opened 15 years ago Closed 15 years ago

[FIX]Speed up RuleProcessorData ctor and SelectorMatches a bit

Categories

(Core :: CSS Parsing and Computation, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: bzbarsky, Assigned: bzbarsky)

References

Details

Attachments

(4 files, 4 obsolete files)

See the "RuleProcessorData and performance" thread in .layout. I decided to go with a fairly conservative fix, in the end; just moving the obvious expensive stuff out of the constructor and reorganizing code a tad.
I also changed the class/id matching to just return PR_FALSE when not matching instead of lugging |result| around. We might want to do a followup to get rid of |result| elsewhere too, but the attr matching was a bit daunting in that respect. ;)
Main changes here: 1) Not writing most of the members twice in the ctor. Those movl calls were showing up all over in the assembly. Moving some more member init into our lazy getters. 2) Not trying to get classes/id if we have no attributes; as long as we're getting the attr count anyway, we might as well do this. Most nodes have no classes/ids. 3) Adding mIsHTML to the RuleProcessorData, since we need this for the common case of tag selectors. 4) Using mParentContent in a few places where for some reason we weren't.
Attachment #407209 - Flags: review?(dbaron)
For reference, these give me about a 20% speedup or so on http://www2.webkit.org/perf/slickspeed/ (goes from 620ms to 500ms or so on my hardware) for the querySelector column.
Attachment #407207 - Flags: review?(dbaron)
Attachment #407209 - Attachment is obsolete: true
Attachment #407321 - Flags: review?(dbaron)
Attachment #407209 - Flags: review?(dbaron)
I just realized that part 1 means I should perhaps remove this comment in SelectorMatches: // The selectors for which we set node bits are, unfortunately, early // in this function (because they're pseudo-classes, which are // generally quick to test, and thus earlier). If they were later, // we'd probably avoid setting those bits in more cases where setting // them is unnecessary. David, thoughts?
Blocks: 523294
Comment on attachment 407208 [details] [diff] [review] Part 2. Main guts of the speed improvement: get mLinkState/mIsLink/mContentState lazily I had to make one of the assertions in SelectorMatches use LinkState() instead of mLinkState to make this compile in a DEBUG build.
Yeah, I think I might have made that change locally after posting the patches... :(
Summary: Speed up RuleProcessorData ctor and SelectorMatches a bit → [FIX]Speed up RuleProcessorData ctor and SelectorMatches a bit
Comment on attachment 407207 [details] [diff] [review] Part 1. Move class/id matching earlier in SelectorMatches. >+ if (!elementClasses->Contains(classList->mAtom, isCaseSensitive ? eCaseMatters : eIgnoreCase)) { Could you wrap this line at under 80 characters? r=dbaron with that
Attachment #407207 - Flags: review?(dbaron) → review+
Comment on attachment 407208 [details] [diff] [review] Part 2. Main guts of the speed improvement: get mLinkState/mIsLink/mContentState lazily Maybe the |protected| section you're adding to should actually be |private|? Also, the comment for mGotIsLink should say it applies to both mIsLink and mLinkState. (Maybe it should have a more neutral name?) Maybe it's better not to initialize mIsLink and mContentState in the constructor? Then valgrind would catch failure to initialize. (Not sure which is faster, though; initializing big swaths could be faster.) If you do, though, you need to change the assertion in LinkState to check mGotIsLink (and perhaps you should anyway). r=dbaron
Attachment #407208 - Flags: review?(dbaron) → review+
Comment on attachment 407321 [details] [diff] [review] Part 3 fixed to properly set mIsLink to false as needed. r=dbaron (And it looks like this addresses the third of my comments on patch 2, except for the assertion in LinkState.)
> Could you wrap this line at under 80 characters? Done. > Maybe the |protected| section you're adding to should actually be |private|? Done. Made mLanguage and mNthIndices private too. > (Maybe it should have a more neutral name?) Renamed to mGotLinkInfo and commented better. > change the assertion in LinkState to check mGotIsLink Good catch. Done.
Attachment #407207 - Attachment is obsolete: true
Attachment #407208 - Attachment is obsolete: true
Attachment #407321 - Attachment is obsolete: true
Attachment #414303 - Attachment is patch: true
Attachment #414303 - Attachment mime type: application/octet-stream → text/plain
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: