Closed Bug 1543055 Opened 6 years ago Closed 6 years ago

AllocationSiteKey hashing can cause quadratic behavior

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla68
Tracking Status
firefox68 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

The testcase below runs in 42 ms. Now if you change |var x = i| to |var x = 0|, we hit a terrible perf cliff and it takes > 6700 ms.

What's happening is that AllocationSiteKey::hash uses the bytecode pc but AllocationSiteKey::match uses script + offset. This breaks down when a ton of scripts use the same underlying bytecode because they'll all have the same hash.

Noticed this while looking into bug 1542995.


function test() {
    var arr = [];
    for (var i = 0; i < 50000; i++) {
        var x = i;
        var f = Function("return [Math, " + x + "]");
        arr.push(f);
    }
    var t = new Date;
    for (var i = 0; i < arr.length; i++) {
        arr[i]();
    }
    print(new Date - t);
}
test();
Type: task → defect

This also uses HashGeneric/AddToHash instead of manual XOR'ing.

As suggested on IRC, it might make sense to give every script a unique ID if this operation is common, and save adding/looking one up in the unique ID hash table.

Pushed by jdemooij@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/21ee37c5b888 Fix AllocationSiteKey hashing to not have quadratic behavior when many scripts share bytecode. r=jonco
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68
Regressions: 1571682
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: