-
Notifications
You must be signed in to change notification settings - Fork 27.4k
refactor(*): replace HashMap
with NgMap
#15483
Conversation
For the time being, we will be using `NgMap`, which is an API-compatible implementation of native `Map` (for the features required in Angular). This will make it easy to switch to using the native implementations, once they become more stable. Note: At the momntm some native implementations are still buggy (often in subtle ways) and can cause hard-to-debug failures.)
this.$get = [function() { | ||
return HashMap; | ||
return NgMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we feature detect native Map
implementation and just use that if present? It should be significantly faster than this implementation since lookups are not O(n), and all modern browsers support it at this point. This fallback is really just for like...IE9 and IE10.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I just saw the comments above because reading fail. What subtle bugs in native Maps exist such that we shouldn't use them for perf, other than IE11 return values not conforming to the spec? Can we add references to filed issues such that when these bugs are fixed, we know that it's safe to migrate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some discussion in #15114. It is not as much about specific bugs as it is about our lack of confidence that there aren't any (or that our tests would have caught them).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(For example, there was some Safari 8 bug (which I couldn't even figure out what it was) that caused our tests to fail, even if the required features were theoretically available.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With that logic, the native Map will never be used as there is no concrete way to judge whether or not they're "ready" - that's why I was suggesting we put some kind of comment in here that "when these things are fixed, re-evaluate"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"when these things are fixed, re-evaluate"
Sounds great. If we only knew what these things were... 😞
So I know we were debating this in that other issue, but I still think an implementation closer to It would not be a breaking change since due to how it worked, the old HashMap implementation could never support frozen objects anyway since it did a property assignment on them. This mainly affects IE9/IE10 though since in newer browsers, we should just use the native implementation. |
According to my understanding, the discussion on #13209 was not conclusive on whether our implementation of Furthermore, this benchmarking would only make sense for The main benefit of using I suggest we merge this (which is just a refactoring - not a |
JSPerf is down at the moment so I can't do any basic tests, but do you have any stats on what the average size of a Map is versus the max size? If N is low enough in your use cases, it's possible that it's fast enough, but I suspect that it'd breakdown with larger maps. Will try to test once I can make some benchmarks. No matter what we do, I am 100% in agreement that we should refactor any APIs to use a |
I assume "people" is "you" 😛 The problem is that not all cases retrieve
(In the future, it may also be used by
|
Yep. I tinker with a lot of internals for fun/performance sometimes, but always with the understanding that nothing I do is supported. Almost have an entire implementation of Observable bindings working that only participate in the digest cycle when necessary - including interpolation in templates and a new Anyway, I will try to run some basic perf tests when JSPerf is back up. |
// // | ||
// s6 | ||
|
||
// s1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks unrelated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong indentation is always relevant! 😛
} | ||
window.document.$$hashKey = null; | ||
// These Nodes are persisted across tests. | ||
// They used to be assigned a `$$hashKey` when animated, but not any more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this could be more explicit. If you read this in a year , would you know hat this means?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You wouldn't? 😱
Updated the comment just in case 😛
PTAL |
LGTM |
For the time being, we will be using `NgMap`, which is an API-compatible implementation of native `Map` (for the features required in Angular). This will make it easy to switch to using the native implementations, once they become more stable. Note: At the moment some native implementations are still buggy (often in subtle ways) and can cause hard-to-debug failures.) Closes #15483
For the time being, we will be using `NgMap`, which is an API-compatible implementation of native `Map` (for the features required in Angular). This will make it easy to switch to using the native implementations, once they become more stable. Note: At the moment some native implementations are still buggy (often in subtle ways) and can cause hard-to-debug failures.) Closes angular#15483
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Refactoring.
What is the current behavior? (You can also link to an open issue here)
Same old, same old!
What is the new behavior (if this is a feature change)?
HashMap
is replaced withNgMap
, which for the time being points toNgMapShim
, an API-compatibleMap
implementation (for the features Angular needs). This will allow us to easily switch to native implementations once they become more stable.Does this PR introduce a breaking change?
No.
Please check if the PR fulfills these requirements
Docs have been added / updated (for bug fixes / features)Other information:
See #13209 and #15114 for related discussions.