Closed Bug 1799154 Opened 3 years ago Closed 6 months ago

Inline Map/Set set

Categories

(Core :: JavaScript Engine: JIT, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED

People

(Reporter: calixte, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: perf)

It seems that Map.prototype.set and Set.prototype.add haven't been inlined in bug #1341265 which was about Map/Set operations.
We'd like use more Map objects in pdf.js but because of some bad performances we don't (see https://github.com/mozilla/pdf.js/commit/3ad6303893365b7ad2e2a723d25498f9f1e2792c for context).
:anba, is it an oblivion ? or is there a good reason to not do that ?

Flags: needinfo?(andrebargull)
Blocks: sm-jits
Severity: -- → N/A
Priority: -- → P2

Inlining Map.prototype.set and Set.prototype.add is more tricky, because it may involve memory allocations when adding new entries, which need to happen in the VM and can't be inlined. Furthermore adding entries may require performing GC barriers, which also needs to happen in the VM. And we also need to call into the VM when using non-JSAtom strings as the keys, but this is also true for Map.prototype.{get,has} and Set.prototype.has.

So before attempting to somehow inline these operations, I'd first check if the pdf.js use case is actually applicable for a possible inlined implementation. (This will require modifying the MapObject class to perform some extra tracking/logging to check if all inputs allow to omit performing VM calls.) Alternatively OrderedHashTable could be profiled to check if there are any low hanging fruits which could be optimised. For example OrderedHashTable eagerly allocates its underlying memory structures and has a small initial capacity. Every trunc((8 / 3) * (1 << N)) element triggers a resize of the hashtable, starting at N=1, so adding a 5th, 10th, 21st, 42nd, 85th, etc. element triggers a resize. mozilla::HashMap supports lazy allocation and has a larger initial capacity, so there are fewer reallocations for small maps.

Flags: needinfo?(andrebargull)

With the recent work in Bug 1851662 and dependents, is this still slow for you?

Flags: needinfo?(cdenizet)
See Also: → 1851662
Flags: needinfo?(cdenizet)

Looks like this is fixed. I will close this, but feel free to reopen if you disagree!

Status: NEW → RESOLVED
Closed: 6 months ago
Depends on: 1851662
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.