Closed Bug 1812828 Opened 2 years ago Closed 2 years ago

Use AutoTArray in ChildCommandDispatcher to avoid reallocation overhead

Categories

(Core :: DOM: Core & HTML, defect)

defect

Tracking

()

RESOLVED FIXED
111 Branch
Tracking Status
firefox111 --- fixed

People

(Reporter: dholbert, Assigned: dholbert)

References

(Blocks 1 open bug)

Details

(Whiteboard: [sp3])

Attachments

(1 file)

ChildCommandDispatcher two local nsTArray variables:
https://searchfox.org/mozilla-central/rev/ef5dad8c11a556acd68ca3b9dcd77b226e0aaa29/dom/base/nsGlobalWindowOuter.cpp#6394,6404-6406

class ChildCommandDispatcher : public Runnable {
...
  NS_IMETHOD Run() override {
    nsTArray<nsCString> enabledCommands, disabledCommands;
    mRoot->GetEnabledDisabledCommands(enabledCommands, disabledCommands);

In a local speedometer run, I got two samples where we were calling AppendElement on one of those arrays:
https://share.firefox.dev/3XEzrCj

I did a local run to print out the sizes of these arrays, to see what the space-of-common-values is like, on my linux system at least. During a Speedoometer 3 run, enabledCommands topped out at 62, while disabledCommands topped out at 70.

So, let's just use AutoTArray with capacity 70 for both of these, to avoid reallocation churn. (Even if we occasionally overshoot 70 by a bit, we'll probably only have to dynamically allocate once, instead of several times.)

This patch doesn't change user-visible behavior.

The AutoTArray size that I'm using, 70, comes from the maximum values that I
observed for these arrays, during a local run of Speedometer 3 on Linux. The
largest 'disabledCommands' array that I encountered had length 70 (and this was
the most common length that this array had); while the largest
'enabledCommands' array was only a bit smaller, with a length of 62.

Pushed by dholbert@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/4fd7b9c658f2 Use AutoTArray for local arrays in ChildCommandDispatcher. r=smaug
Severity: -- → S3
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 111 Branch
Whiteboard: [sp3]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: