Closed Bug 1380344 Opened 7 years ago Closed 7 years ago

Ion-inline IsPackedArray

Categories

(Core :: JavaScript Engine: JIT, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla56
Tracking Status
firefox56 --- fixed

People

(Reporter: anba, Assigned: anba)

Details

Attachments

(1 file, 1 obsolete file)

      No description provided.
Attached patch bug1380344.patch (obsolete) — Splinter Review
Jan, do you think it makes sense to inline IsPackedArray the way this patch does?

The patch improves this µ-benchmark from ~150ms to ~105ms for me:

    var a = [1];
    var q = 0;
    var t = Date.now();
    for (var i = 0; i < 1000000; ++i) {
        var c = [].concat(a);
        q += c.length;
    }
    print(Date.now() - t, q);
Attachment #8885754 - Flags: feedback?(jdemooij)
Comment on attachment 8885754 [details] [diff] [review]
bug1380344.patch

Review of attachment 8885754 [details] [diff] [review]:
-----------------------------------------------------------------

Yes this makes a lot of sense!

::: js/src/jit/CodeGenerator.cpp
@@ +12747,5 @@
> +
> +    Label notPacked, done;
> +
> +    // Load elements and length.
> +    RegisterOrInt32Constant key = RegisterOrInt32Constant(lengthTemp);

Nit: you can use the register directly instead of RegisterOrInt32Constant. I'd also use |output| instead of lengthTemp so things are a bit easier for the register allocator.

::: js/src/jit/MCallOptimize.cpp
@@ +1766,5 @@
> +        return InliningStatus_NotInlined;
> +
> +    const Class* clasp = arrayTypes->getKnownClass(constraints());
> +    if (clasp != &ArrayObject::class_)
> +        return InliningStatus_NotInlined;

It might be interesting to check if we ever see cases where clasp is not nullptr but some other Class. In that case we can fold this to |false| at compile time.

::: js/src/jit/MIR.h
@@ +13807,5 @@
> +class MIsPackedArray
> +  : public MUnaryInstruction,
> +    public SingleObjectPolicy::Data
> +{
> +    MIsPackedArray(MDefinition* array)

Nit: explicit

@@ +13816,5 @@
> +
> +  public:
> +    INSTRUCTION_HEADER(IsPackedArray)
> +    TRIVIAL_NEW_WRAPPERS
> +    NAMED_OPERANDS((0, array))

Nit: can override getAliasSet here and call setMovable() in the constructor. See MInitializedLength for instance.
Attachment #8885754 - Flags: feedback?(jdemooij) → feedback+
(In reply to Jan de Mooij [:jandem] from comment #2)
> ::: js/src/jit/MCallOptimize.cpp
> @@ +1766,5 @@
> > +        return InliningStatus_NotInlined;
> > +
> > +    const Class* clasp = arrayTypes->getKnownClass(constraints());
> > +    if (clasp != &ArrayObject::class_)
> > +        return InliningStatus_NotInlined;
> 
> It might be interesting to check if we ever see cases where clasp is not
> nullptr but some other Class. In that case we can fold this to |false| at
> compile time.

Hmm, IsPackedArray is currently only called in four places in self-hosted code (Array.p.concat, Array.p.reduce[Right], and Reflect.construct) and I have a hard time predicting which of these callers, if any, may use a non-Array object. So, I'm not really sure if we need to handle this case. :-/
(In reply to Jan de Mooij [:jandem] from comment #2)
> @@ +13816,5 @@
> > +
> > +  public:
> > +    INSTRUCTION_HEADER(IsPackedArray)
> > +    TRIVIAL_NEW_WRAPPERS
> > +    NAMED_OPERANDS((0, array))
> 
> Nit: can override getAliasSet here and call setMovable() in the constructor.
> See MInitializedLength for instance.

I also needed to add Op_IsPackedArray to GetObject in AliasAnalysisShared.cpp to avoid this assertion: http://searchfox.org/mozilla-central/rev/cbd628b085ac809bf5a536109e6288aa91cbdff0/js/src/jit/AliasAnalysisShared.cpp#158
Attached patch bug1380344.patchSplinter Review
I've updated the patch with your suggestions from comment #2.
Attachment #8885754 - Attachment is obsolete: true
Attachment #8886535 - Flags: review?(jdemooij)
Comment on attachment 8886535 [details] [diff] [review]
bug1380344.patch

Review of attachment 8886535 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks!
Attachment #8886535 - Flags: review?(jdemooij) → review+
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/477268fa767f
Add Ion support for IsPackedArray. r=jandem
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/477268fa767f
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla56
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: