Open Bug 2097960 Opened 2 days ago Updated 18 hours ago

Allocate Map and Set iterators in JIT code and inline their self-hosted next methods

Categories

(Core :: JavaScript Engine: JIT, enhancement)

enhancement

Tracking

()

UNCONFIRMED

People

(Reporter: perf-ai-bot, Unassigned)

References

(Blocks 2 open bugs)

Details

(Whiteboard: [foofrix:a7f2458a-d993-4ee4-a535-9ed848c8f52f])

Attachments

(1 external file)

Inline public Map/Set iterator creation in Baseline CacheIR and Warp, including implicit iterator calls. Allocate and link nursery iterators using cached shapes for eligible same-realm calls, retaining C++ fallbacks for missing nursery registration, a deleted first entry or unavailable inline allocation. Exclude getters and allocation metadata builders. Allow large-function inlining of the self-hosted next methods so scalar replacement can eliminate non-escaping result objects. Extend tests for collection lifetimes and allocation tracking enabled after warmup.

Problem

Map and Set iterator creation uses generic native calls, and implicit iterator calls were excluded from native inlining. Their self-hosted next methods also exceed the normal trial-inlining size limit, limiting elimination of result objects in callers. Repeated Map iteration in sync-fs directory listings motivated optimizing these paths.

Performance

  • Benchmark: jetstream3-sync-fs
  • Suite: jetstream3
  • Test: js3-sync-fs-spidermonkey
  • Component: JS
  • Local Improvement: 7.49%

Validation

Blocks: jetstream3

Please move this bug to the correct component.

Once the Phabricator patch is ready for review, please commandeer it.

Flags: needinfo?(iireland)

Creating a Map or Set iterator always calls the native entries, keys or
values method, which looks up the iterator prototype and initial shape,
allocates the iterator and links it into the collection's list of live
iterators. Implicit @@iterator calls (JSOp::CallIter, used by for-of,
spread and destructuring, and its self-hosted variant
JSOp::CallContentIter) never considered inlinable natives at all. The
self-hosted MapIteratorNext and SetIteratorNext also exceed the
trial-inlining size limit, so callers can't inline them and scalar
replace the result objects they return.

Make Map.prototype.entries, keys and values and Set.prototype.entries
and values inlinable natives, which also covers
Map.prototype[@@iterator], Set.prototype.keys and
Set.prototype[@@iterator], and consider inlinable natives at CallIter
and CallContentIter. For calls without arguments whose target and
receiver are in the current realm, Baseline CacheIR stubs and Warp's new
MNewTableIterator allocate the iterator in the nursery with a shape
cached at attach time and link it into the collection's list of nursery
iterators. Getter calls aren't optimized because Ion property ICs don't
support the new ops, nor are calls in realms with an allocation metadata
builder.

The JIT code falls back to the existing C++ path when the collection
isn't registered with the nursery as having nursery iterators (as for
its first iterator, or the first one after a minor GC that left it with
none), when its first entry was deleted so a new iterator would have to
skip over it, or when inline allocation fails. Both iterator classes are
foreground finalized but skip nursery finalization, so the debug
assertion in nurseryAllocateObject now accepts them when the caller
passes the class. The std_Map_entries and std_Set_values intrinsics used
by self-hosted code keep calling the natives.

Mark MapIteratorNext and SetIteratorNext as inlinable large functions,
as ArrayIteratorNext and StringIteratorNext already are, so trial
inlining can inline them and scalar replacement can remove their
non-escaping result objects.

New jit-tests cover the iterator kinds, mutations during iteration,
iterators kept alive across GCs, collection lifetimes, realms,
subclasses, bound functions, getters and an allocation metadata builder
enabled after warm-up.

V8 similarly allocates collection iterators inline in
JSCreateLowering::ReduceJSCreateCollectionIterator
(src/compiler/js-create-lowering.cc) and inlines next() in
JSCallReducer::ReduceCollectionIteratorPrototypeNext
(src/compiler/js-call-reducer.cc). Its iterators only hold a table and
an index, while SpiderMonkey also links each iterator into its
collection so it can be updated when entries are removed or the table is
compacted or cleared.

In addition to improving sync-fs, this also appears to be a 2-5% improvement in the ChatStream-Octane test in SPX.

Type: defect → enhancement
Component: Performance: Automated Findings → JavaScript Engine: JIT
Flags: needinfo?(iireland)
Blocks: 2098740
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: