Closed Bug 704174 Opened 13 years ago Closed 10 years ago

nsTArray: Investigate the benefits and costs of boxed mHdr

Categories

(Core :: XPCOM, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED INCOMPLETE

People

(Reporter: bjacob, Unassigned)

References

Details

Attachments

(1 file)

nsTArray only stores a pointer |mHdr| to a Header, which contains all the data: mLength, mCapacity, mIsAutoArray, followed by the actual storage of array elements.

The benefit is that empty arrays use only sizeof(void*) bytes, as their |mHdr| pointer points to a shared sEmptyHdr object.

The possible drawbacks are:
 - more complex source code
 - more complex array indexing (have to add sizeof(Header) bytes to address array elements)
 - one more dereference needed to address mLength, mCapacity, mIsAutoArray.

Justin has commented on this: bug 677571 comment 46 and bug 677571 comment 47.

Here's a patch counting the maximum (peak) number of empty nsTArrays that we reach during Firefox's lifetime.

Some results:

empty session:                                9181
nytimes.com:                                 16056
arstechnica.com:                             19162
nytimes.com + arstechnica.com:               25120
youtube.com:                                 19403
nytimes.com + arstechnica.com + youtube.com: 35350

So the conclusion is that the peak number of empty nsTArrays is, in practice, as a very rough approximation, roughly given by this formula:

    9000 * (1 + max_number_of_nondefault_tabs)

Of course this can vary depending on what the page does. This is just out of a sample of 3 mainstream pages.

Anyway, 9000 empty nsTArrays per tab.

The mHdr boxing saves us 8 bytes per empty nsTArray, so the conclusion is that mHdr boxing saves ~ 70k per tab.
Most of the source code simply dereferences mHdr without any branches, which is pretty readable and should be fast in compiled code.

Are there any next steps for this bug? 70k per tab seems significant to me.
Not necessarily; I just wanted it to be a place to gather data and make sure that this has been considered. Feel free to close.
Closing as per comment 2, though I think Benoit has replicated this work in other bugs. ;)
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: