Closed Bug 1920433 Opened 24 days ago Closed 22 days ago

Improve InlineTable data structure

Categories

(Core :: JavaScript Engine, task, P1)

task

Tracking

()

RESOLVED FIXED
132 Branch
Tracking Status
firefox132 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

Details

Attachments

(6 files)

I'm using InlineMap for bug 1920430, but I noticed it has a number of issues:

  • Removed inline entries are set to a tombstone value, but are never reused. This means we can expand to a full HashMap/HashSet before using all inline entries.
  • Support was added for customizing tombstone values through KeyPolicy, but this is incomplete. There are still multiple places where we rely on key values being 'truthy'.
  • Tombstone values add some complexity - see the separate inlCount_ vs inlNext_ fields.

It's simpler to implement removal by swapping the last item in the array with the removed item.

Also, the class contains both an array of inline entries and a HashMap/HashSet. We can save space by using a Variant.

Also use private instead of protected in a few places.

InlineTable supports customizing tombstone values through KeyPolicy, but this was
incomplete. Some places still relied on valid keys being 'truthy'.

Also, removed inline entries were never reused. This means we could expand to a
HashMap/HashSet before using all inline entries.

This patch implements removal by swapping the removed item with the last item.
This also lets us merge the inlNext_ and inlCount_ fields.

A later patch will add mutationCount assertions to ensure we don't remove items
from the table while iterating.

This is more memory efficient and also means we don't initialize the
HashMap/HashSet if it's not used.

Also use uint32_t instead of size_t to save some space. This will never be a
large value.

Add assertions to check no entries are added/removed while using Ptr/AddPtr or Range.

Pushed by jdemooij@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7933f2426217 part 1 - Remove dead code from InlineTable.h. r=arai https://hg.mozilla.org/integration/autoland/rev/67349f52462c part 2 - Don't use tombstones for removed inline entries in InlineTable. r=arai https://hg.mozilla.org/integration/autoland/rev/e41d64b380a3 part 3 - Use Variant for InlineTable array/table. r=arai https://hg.mozilla.org/integration/autoland/rev/a04d374230a3 part 4 - Rename InlineArray::inlCount to InlineArray::count. r=arai https://hg.mozilla.org/integration/autoland/rev/2390753f710e part 5 - Add assertions to check for mutations. r=arai https://hg.mozilla.org/integration/autoland/rev/e88470b69a09 part 6 - Use reserve() in InlineTable::switchToTable. r=arai
Severity: -- → N/A
Priority: -- → P1
Regressions: 1922242
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: