Closed Bug 1868857 Opened 2 years ago Closed 10 months ago

Suppress deleted properties using low-bit tags instead of removal

Categories

(Core :: JavaScript Engine, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
145 Branch
Tracking Status
firefox145 --- fixed

People

(Reporter: iain, Assigned: alexical)

References

(Depends on 1 open bug, Blocks 1 open bug)

Details

(Whiteboard: [sp3])

Attachments

(1 file, 2 obsolete files)

We implement for-in enumeration using NativeIterator, an object with a trailing array of strings that we expect to return as keys. To handle cases where a property is deleted while we are iterating the object, we link NativeIterators into a linked list while active. When a property is deleted, we check to see if it is currently being iterated, and if so, we fix up the NativeIterator.

Currently we do so by mutating the trailing array to remove deleted keys (if we haven't already visited them). This unfortunately means that we can't reuse the iterator again for a subsequent object with the same shape. It also means that we can't simply reuse the cached NativeIterator to do scalar replacement of Object.keys.

Jan suggested that instead of removing keys entirely, we could simply tag them as deleted, and skip deleted keys in MoreIter. This lets us reuse the NativeIterator (by untagging all deleted keys when we're done iterating). It also lets Object.keys use the same NativeIterator, even if there's an active enumeration, by simply ignoring the tag bit. We end up with NativeIterators that are still mutable where necessary for for-in, but immutable from the point of view of Object.keys.

Attached file WIP: (WIP) Bug 1868857: Hacky barrier (obsolete) —

Depends on D195807

Blocks: 1914502
Whiteboard: [sp3]
Assignee: nobody → dothayer

This is adapted from Iain's patch in the linked bug. We want
to be able to scalar replace Object.keys when its result is just
going to be iterated over and not escape. We should be able to
use all the NativeIterator infrastructure for this purpose, but
a critical difference is that if properties are deleted in the
loop, a for in loop will skip those properties, while Object.keys,
being a snapshot, won't. This patch allows us to support both
cases by marking deleted properties with a flag which will be
utilized to filter when iterating normally, and ignored when
iterating an Object.keys result.

Depends on: 1991792
Status: NEW → RESOLVED
Closed: 10 months ago
Resolution: --- → FIXED
Target Milestone: --- → 145 Branch
QA Whiteboard: [qa-triage-done-c146/b145]
Attachment #9367511 - Attachment is obsolete: true
Attachment #9367512 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: