Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use original map for data backing when possible. #429

Merged
merged 1 commit into from
Dec 3, 2016
Merged

Use original map for data backing when possible. #429

merged 1 commit into from
Dec 3, 2016

Conversation

jdalton
Copy link
Contributor

@jdalton jdalton commented Nov 21, 2016

This PR attempts to address #422 by using the original map for data backing when possible to avoid linear lookups.

@ljharb
Copy link
Collaborator

ljharb commented Nov 21, 2016

Thanks!

What about browsers where -0 and 0 are not properly distinguished? There's also insertion order, browsers where iteration completion throws a StopIterator exception, browsers where "size" is a function instead of a getter, browsers where Map and Set aren't iterable except with an eval'd for-of, browsers that lack the facility to clear and create iterators for keys/values/entries and then combined with the fact that the shim itself mutates Map.prototype when it already exists - so you'd need to cache all of the existing prototype methods (like get, has, set, etc), or else you'd risk an infinite loop.

In other words, using the original Map is a great approach, but there are a fractal of issues caused by the very necessity of the shim in the first place :-/

@jdalton
Copy link
Contributor Author

jdalton commented Nov 21, 2016

What about browsers where -0 and 0 are not properly treated?

I was hoping that was handled by the fast path.
If not I'll rework to address it in the fast key path.

There's also insertion order, browsers where iteration completion throws a StopIterator exception,

Do you have a unit test to cover this?
This is internal storage where the fast path has no concept of order since it's an empty object.

browsers where "size" is a function instead of a getter, browsers where Map and Set aren't iterable except with an eval'd for-of,

I'm not using size of the internal map.

browsers that lack the facility to clear and create iterators for keys/values/entries

This doesn't affect our internal map use.

the shim itself mutates Map.prototype when it already exists - so you'd need to cache all of the existing prototype methods (like get, has, set, etc), or else you'd risk an infinite loop.

Ya, I'll address that.

@ljharb
Copy link
Collaborator

ljharb commented Nov 21, 2016

I have a number of test cases that should cover it - you'd need to run the test HTML in a very large number of browsers (which sadly travis doesn't cover) to check it out.

Mind you I'm not saying all these things will definitely cause a problem - more that it's possible, and I want to both be confident in this PR's correctness and also avoid leaving behind a footgun for the future.

@jdalton
Copy link
Contributor Author

jdalton commented Nov 21, 2016

Mind you I'm not saying all these things will definitely cause a problem - more that it's possible, and I want to both be confident in this PR's correctness and also avoid leaving behind a footgun for the future.

Cool. Ya, the use case I'm going for is to be a replacement for the linear search for object keys. That means it just needs to be a black box that is a yay or nay for if an object key is found. It can even go along with the array tracking as just a faster check but defer to the linear backing for when order is important.

@jdalton
Copy link
Contributor Author

jdalton commented Nov 21, 2016

Looks like unit tests pass in IE11 and it resolves the perf issue 🎉

@ljharb
Copy link
Collaborator

ljharb commented Nov 22, 2016

Thanks, I'll give it a thorough review, and do some extensive testing in as many browsers as I can before merging this.

@jdalton
Copy link
Contributor Author

jdalton commented Nov 28, 2016

Tested on Safari 7, 8, 9, 10 and IE 9, 10 with no Map related test fails.

@ljharb
Copy link
Collaborator

ljharb commented Nov 28, 2016

TC39 is this week so I'll need a bit more time to review; rest assured it's still on my list :-)

@ljharb
Copy link
Collaborator

ljharb commented Dec 3, 2016

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants