Closed Bug 1420961 Opened 2 years ago Closed 2 years ago

Clean up iterator code

Categories

(Core :: JavaScript Engine: JIT, enhancement)

enhancement
Not set

Tracking

()

RESOLVED FIXED
mozilla59
Tracking Status
firefox59 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

Details

Attachments

(4 files)

With for-each gone we can remove a bunch of stuff: JSOP_ITER flags operand, JSITER_ENUMERATE, and some checks in code that's pretty hot.
It doesn't use its cx argument and always returns true.
Attachment #8932137 - Flags: review?(evilpies)
In js::GetIterator we return early if the object is a PropertyIteratorObject. I don't see how this is possible since PropertyIteratorObject shouldn't escape to JS. This patch just turns it into an assert.
Attachment #8932138 - Flags: review?(evilpies)
Attachment #8932137 - Flags: review?(evilpies) → review+
Attachment #8932138 - Flags: review?(evilpies) → review+
I thought there was some other reason we didn't want to set the enumerate flags when calling from the Proxy::enumerate hook. Something to do with not putting the iterator object in the iterator list? I will look into that tomorrow.
Part 3 failed browser tests on Try. It turns out the Reify function was never called because in Wrapper::enumerate we would create an iterator with flags = 0 and then in CanReify check for flags & JSITER_ENUMERATE. I think this is a regression from bug 783829.

This patch adds a markId call to Reify and adds a shell test.

Having Reify work again makes some cross-compartment for-in micro-benchmarks > 20% faster.
Attachment #8932468 - Flags: review?(jcoppeard)
Comment on attachment 8932468 [details] [diff] [review]
Part 4 - Add missing markId call

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

Ah, nice.

It's a shame it's so easy to miss marking atoms.
Attachment #8932468 - Flags: review?(jcoppeard) → review+
(In reply to Tom Schuster [:evilpie] from comment #4)
> I thought there was some other reason we didn't want to set the enumerate
> flags when calling from the Proxy::enumerate hook. Something to do with not
> putting the iterator object in the iterator list? I will look into that
> tomorrow.

FWIW I can't think of any issues here. If we wrap an iterator it will be in the enumerator list (of the wrappee's compartment). JSOP_ITEREND may not remove it from that list but that's okay - the enumerator list is a doubly linked list and is swept on GC - it's not a stack that has to stay balanced. Also, when the Reify optimization kicks in we won't use a wrapped iterator but we just copy it and then close the original.
Comment on attachment 8932139 [details] [diff] [review]
Part 3 - Remove JSITER_ENUMERATE and flags arguments

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

Sounds right, thanks Jan. It's great to have that flag removed.
Attachment #8932139 - Flags: review?(evilpies) → review+
Pushed by jandemooij@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/6133d185ba8b
part 1 - Make NativeIteratorNext infallible. r=evilpie
https://hg.mozilla.org/integration/mozilla-inbound/rev/3f9a32b603db
part 2 - Replace if-statement with an assert in js::GetIterator. r=evilpie
https://hg.mozilla.org/integration/mozilla-inbound/rev/bb14fe85b1a9
part 3 - Remove JSITER_ENUMERATE and flags arguments. r=evilpie
https://hg.mozilla.org/integration/mozilla-inbound/rev/649756a338c8
part 4 - Add missing markId call to Reify function. r=jonco
You need to log in before you can comment on or make changes to this bug.