Closed
Bug 72217
Opened 24 years ago
Closed 24 years ago
nsVoidArray::IndexOf called in StyleContextCache::AddContext is accounting for too much time in some cases
Categories
(Core :: CSS Parsing and Computation, defect, P2)
Core
CSS Parsing and Computation
Tracking
()
VERIFIED
FIXED
mozilla0.9
People
(Reporter: attinasi, Assigned: attinasi)
References
Details
(Keywords: perf)
Attachments
(2 files)
350.99 KB,
text/html
|
Details | |
887 bytes,
patch
|
Details | Diff | Splinter Review |
In the code below, IndexOf is called to ensure that the item is not already in
the list, however it gets pretty expensive in cases where there are lots of
entires in the list, and since the assertion
NS_ASSERTION(pList->IndexOf(aContext) == -1, "Context already in list");
is never triggered, it is probably best to remove the check in non-debug builds.
nsresult StyleContextCache::AddContext(scKey aKey, nsIStyleContext *aContext)
{
// verify we have a list
nsresult rv = VerifyList(aKey);
if (NS_SUCCEEDED(rv)){
nsVoidArray *pList = GetList(aKey);
NS_ASSERTION(pList != nsnull, "VerifyList failed me!");
NS_ASSERTION(pList->IndexOf(aContext) == -1, "Context already in list");
if(pList->IndexOf(aContext) == -1){
^^^^^^^ - remove this check
if (!(pList->AppendElement(aContext))) {
rv = NS_ERROR_FAILURE;
} else {
mCount++;
}
DumpStats();
} else {
#ifdef DEBUG
printf( "Context already in list in StyleContextCache::AddContext\n");
#endif
rv = NS_ERROR_FAILURE;
}
}
return rv;
}
In a testcase with lots of unique style contexts (like one from bug 67692, to be
attached here) this IndexOf call accounts for almost 20% of the time in style
sharing.
Assignee | ||
Comment 1•24 years ago
|
||
Assignee | ||
Comment 2•24 years ago
|
||
Quantify shows that out of 8 seconds in style resolution on the attached
testcase, 1.4 is spent in nsVoidArray::IndexOf coming out of AddContext - seems
like a waste.
CC'ing some smart folks for opinions (or flames, or smelly fish).
Comment 3•24 years ago
|
||
Sounds good to me! What would happen if two ended up in the list after all?
Assignee | ||
Comment 4•24 years ago
|
||
I'm not sure, but there is clearly an assumption that the entries in the list
are unique. I think that having multiple entries for a context in the list is
really just a symptom of something more heinous happening, like not being able
to find an entry in the first place. If there were two, then returning the
'wrong' one shouldn't really matter since they are, well, the same object instance.
I think this is a case of me over-protecting the preconditions of an internal
method... bad doggy. The assertion should definitely be enough to enforce the
contract here.
Comment 5•24 years ago
|
||
r=jag if you want it :-)
Assignee | ||
Comment 6•24 years ago
|
||
Comment 8•24 years ago
|
||
sr=brendan@mozilla.org -- I'm curious to know the cause of the "duplicates",
even if benign (before I go klutzing around trying to squeeze out nsHashtable
and nsVoidArrays via pldhash here).
/be
Assignee | ||
Comment 9•24 years ago
|
||
There are never any duplicates. The check was put in (along with an assertion
which is staying) to catch incorrect usage. Since it causes a performance
problem, I am removing the runtime check for duplicates and relying on the
assertion to cath them. However, I have never seen this assertion.
Assignee | ||
Comment 10•24 years ago
|
||
Fixed: nsStyleSet.cpp ver 3.85
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Comment 11•24 years ago
|
||
*** Bug 68030 has been marked as a duplicate of this bug. ***
You need to log in
before you can comment on or make changes to this bug.
Description
•