Closed Bug 1875030 Opened 2 years ago Closed 2 years ago

Marking object elements may be quadratic if there are shifted elements

Categories

(Core :: JavaScript: GC, defect, P2)

defect

Tracking

()

RESOLVED FIXED
124 Branch
Tracking Status
firefox-esr115 --- fixed
firefox124 --- fixed

People

(Reporter: jonco, Assigned: jonco)

References

Details

Attachments

(2 external files, 1 obsolete file)

I found a bug in the way we handle indexes into object element ranges when accounting for shifted elements and this may lead to quadratic marking time for those elements.

The mark stack mark hold indexes into object elements to track the progress of marking those elements. The mutator may shift these elements which would invalidate any index we hold. The idea is that we fix and of these indexes by subtracting the shifted elements count.

Unfortunately however this is not performed once at the start of marking but every time we read the range off the mark stack. Since we use depth first traversal for marking this can happen for every element. This causes us to loop over these elements repeatedly as we reset the index to zero every time. We check whether the GC things are already marked so this does not cause to loop forever. Also, the number of elements we loop over is limited by the number of shifted elements, so this is not likely to be a big problem in practice.

Test case to reproduce the issue:

const size = 1000000;

gc();

let a = new Array(size);

for (let i = 0; i < size; i++) {
  if (i < size / 2) {
    a[i] = 0;
  } else {
    a[i] = { x: i };
  }
}
for (i = 0; i < size / 2; i++) {
  a.shift();
}

let start = performance.now();
gc();
let end = performance.now();
print(`Time: ${end - start} ms`);

Current result: 543.41 ms
Result with patch: 8.02 ms

Severity: -- → S3
Priority: -- → P2
Pushed by jcoppeard@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/27ddbf31966b Update element ranges on the mark stack before and after marking to take account of shifted elements r=sfink,jandem
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 124 Branch
Blocks: 1889355
Attachment #9403464 - Attachment is obsolete: true

Comment on attachment 9403465 [details]
Bug 1875030 - Update element ranges on the mark stack before and after marking to take account of shifted elements (ESR115)

ESR Uplift Approval Request

  • If this is not a sec:{high,crit} bug, please state case for ESR consideration: Requesting uplift as this is a dependency of bug 1889355, which is sec-high.
  • User impact if declined: Bug 1889355: Possible crash / security vulnerability.
  • Fix Landed on Version: 124
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): The fix has been on central for 4 months without regressions.

A patch has been attached on this bug, which was already closed. Filing a separate bug will ensure better tracking. If this was not by mistake and further action is needed, please alert the appropriate party. (Or: if the patch doesn't change behavior -- e.g. landing a test case, or fixing a typo -- then feel free to disregard this message)

Comment on attachment 9403465 [details]
Bug 1875030 - Update element ranges on the mark stack before and after marking to take account of shifted elements (ESR115)

Approved for 115.12esr.

Attachment #9403465 - Flags: approval-mozilla-esr115+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: