Closed Bug 826951 Opened 13 years ago Closed 13 years ago

JS::HashTable does not compact enough if most of its elements are removed by an Enum

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla21

People

(Reporter: justin.lebar+bug, Assigned: justin.lebar+bug)

Details

Attachments

(1 file, 1 obsolete file)

In ~Enum(), we call checkUnderloaded(). As I understand it, this compacts the table by half if it's underloaded. But what if we removed more than half of the table's elements during the Enum()? Shouldn't we compact more, in this case? I ran into this in bug 826515; there, we may well delete a large portion of a large (tens of mb) hashtable in one go.
I picked a bad base rev for that last push, but I think it was basically fine aside from the known failures. I pushed again to be sure. https://tbpl.mozilla.org/?tree=Try&rev=38fadb1f935c
Attached patch Patch, v1 (obsolete) — Splinter Review
I think we could be more efficient with how we calculate the new size, but it's not simple, and I'm not sure it's worth worrying about. What do you think?
Attachment #698643 - Flags: review?(luke)
Assignee: general → justin.lebar+bug
Great find! Could you factor out the underloaded computation (capacity > sMinSize && entryCount < ((sMinAlphaFrac * capacity) >> 8)) between underloaded() and compactIfUnderloaded() into a static function?
Attached patch Patch, v2Splinter Review
Attachment #698643 - Attachment is obsolete: true
Attachment #698643 - Flags: review?(luke)
Attachment #698940 - Flags: review?(luke)
Comment on attachment 698940 [details] [diff] [review] Patch, v2 Review of attachment 698940 [details] [diff] [review]: ----------------------------------------------------------------- Very nice ::: js/public/HashTable.h @@ +956,5 @@ > + // Would the table be underloaded if it had the given capacity and entryCount? > + static bool wouldBeUnderloaded(uint32_t capacity, uint32_t entryCount) > + { > + return capacity > sMinSize && > + entryCount <= ((sMinAlphaFrac * capacity) >> 8); We've extended the column limit to 99, so this can all be on one line.
Attachment #698940 - Flags: review?(luke) → review+
I noticed that the comment on compactIfUnderloaded was out of date. I changed it to: // Resize the table down to the largest capacity which doesn't underload the // table.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla21
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: