Closed Bug 1166709 Opened 10 years ago Closed 10 years ago

for-of loops are ~6x slower with unboxed objects.

Categories

(Core :: JavaScript Engine: JIT, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla41
Tracking Status
firefox41 --- fixed

People

(Reporter: nbp, Assigned: bhackett1024)

References

Details

Attachments

(2 files)

As reported in bug 1165348 comment 7, using unboxed objects on misc-basic-array-forof [1] cause a ~6x slow down. (~3.3s vs. ~560ms) [1] https://github.com/nbp/arewefastyet/blob/iterator-loops/benchmarks/misc/tests/assorted/misc-basic-array-forof.js
Flags: needinfo?(bhackett1024)
Blocks: 1106828
Attached patch part 1Splinter Review
When a 'new' object is converted from unboxed to native, we invalidate things so that calling 'new' on the same script will create native objects in the future. There isn't a similar mechanism for initializer objects, and in this case we keep creating unboxed objects in self hosted code for 'for of' and immediately converting them to natives, which is expensive. The attached patch adds a mechanism for this invalidation, along with some perf improvements for NEWOBJECT with dynamic slots. This improves my time with unboxed objects from a 10x slowdown to a 20% slowdown. There is still more to do; after creating the object we have a 'SetPropertyCache; GuardShape; Slots; StoreSlot' series of instructions to initialize the object, rather than 'Slots; StoreSlot; StoreSlot' like we should.
Assignee: nobody → bhackett1024
Flags: needinfo?(bhackett1024)
Attachment #8608208 - Flags: review?(jdemooij)
Keywords: leave-open
Attached patch part 2Splinter Review
Improve type information so that we know the new NEWOBJECT group has definite properties. This fixes the codegen issue around initializing these objects, but doesn't speed things up any more. The bottleneck seems to be the larger size of the objects we are creating now --- Slots0 + 8 dynamic slots compared to Slots2 with no dynamic slots. A couple things: - We might want to think about lowering SLOT_CAPACITY_MIN sometime. It made sense when slot arrays were all dynamically allocated, but maybe not so much now that we have a generational GC. If I reduce this constant to 2, I see a difference of 2% with/without unboxed objects instead of 20%. - Does scalar replacement work on this testcase? If I use --ion-scalar-replacement=off it doesn't affect perf for me, whether I am using unboxed objects or not.
Attachment #8608228 - Flags: review?(jdemooij)
(In reply to Brian Hackett (:bhackett) from comment #2) > - Does scalar replacement work on this testcase? If I use > --ion-scalar-replacement=off it doesn't affect perf for me, whether I am > using unboxed objects or not. Scalar replacement no longer works on iterators because of a spec change, this is what Bug 1165348 address.
(In reply to Nicolas B. Pierron [:nbp] from comment #3) > (In reply to Brian Hackett (:bhackett) from comment #2) > > - Does scalar replacement work on this testcase? If I use > > --ion-scalar-replacement=off it doesn't affect perf for me, whether I am > > using unboxed objects or not. > > Scalar replacement no longer works on iterators because of a spec change, > this is what Bug 1165348 address. Yes, this fix the issue, when Bug 1165348 patch is applied I have the following result: --ion-scalar-replacement=off 618.037 ms --ion-scalar-replacement=on 345.105 ms On the other hand I got the following assertion when testing with a debug build: Assertion failure: shape->numFixedSlots() == NativeObject::MAX_FIXED_SLOTS || maybeOriginalUnboxedGroup(), at js/src/vm/TypeInference.cpp:2649
Blocks: 1166711
Attachment #8608208 - Flags: review?(jdemooij) → review+
Attachment #8608228 - Flags: review?(jdemooij) → review+
The above push is a partial fix for this bug (the full patch had some weird try failures I haven't figured out yet) which maintains the perf improvement on this testcase but isn't generating optimal code quite yet.
The above push marks the properties in the replacement group as definite, though the replacement group can still have a different / more appropriate allocation kind than the original unboxed group. This fixes the codegen issue around initializing these objects. The full patch still has weird problems on try, and since trying to keep the allocation kinds consistent in these replacement groups is kind of a dubious design strategy anyways, I think this fix should be sufficient for this bug.
Keywords: leave-open
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla41
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: