Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 can think of a couple of reasons; one is just that you've switched (I think?) the mapped type to be homomorphic by specifically doing
N in Node as N["type"]
; this may actually end up being a behavior change just due to how these mappings work...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.
No obvious outward differences jumped out at me between the two kinds of mapped types at the bottom of this little playground (albeit it's hard to see the whole picture) besides the aforementioned speed. Can you think of what the downstream behavioural changes may be? If so I'm happy to investigate a bit further.
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'll be honest and say that I'm not an expert here; @weswigham would probably know how to better reason about this as I'm more or less parroting off of others 😄
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.
Extract
is distributive, so operates over every member of theNode
passed in - so for every key inNode["type"]
previously it was iterating over everyNode
type to find and select the desired type (exponential behavior). Now, instead, for each member ofNode
, we only create a single property and execute a single conditional over that member. We're just iterating over less.