Skip to content

Commit

Permalink
Bug 1811750 - Eliminate redundant array filling in performance.measur…
Browse files Browse the repository at this point in the history
…e r=sefeng

Basically we were falling off a cliff where if we had a bunch of marks recorded
with a particular name, when trying to measure we would fill an array with all
of them only to return the last one. This just replaces that by iterating in
reverse and returning the first matching mark. Arguably we should be using a
hashmap or something here, but this is a quick and trivial improvement that I
think will resolve the reported issue.

Differential Revision: https://phabricator.services.mozilla.com/D199451
  • Loading branch information
squarewave committed Jan 24, 2024
1 parent 15e600c commit 3956b52
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions dom/performance/Performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,17 +396,15 @@ DOMHighResTimeStamp Performance::ConvertMarkToTimestampWithString(
return ConvertNameToTimestamp(aName, aRv);
}

AutoTArray<RefPtr<PerformanceEntry>, 1> arr;
Optional<nsAString> typeParam;
nsAutoString str;
str.AssignLiteral("mark");
typeParam = &str;
GetEntriesByName(aName, typeParam, arr);
if (!arr.IsEmpty()) {
if (aReturnUnclamped) {
return arr.LastElement()->UnclampedStartTime();
RefPtr<nsAtom> name = NS_Atomize(aName);
// Just loop over the user entries
for (const PerformanceEntry* entry : Reversed(mUserEntries)) {
if (entry->GetName() == name && entry->GetEntryType() == nsGkAtoms::mark) {
if (aReturnUnclamped) {
return entry->UnclampedStartTime();
}
return entry->StartTime();
}
return arr.LastElement()->StartTime();
}

nsPrintfCString errorMsg("Given mark name, %s, is unknown",
Expand Down

0 comments on commit 3956b52

Please sign in to comment.