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

updateInDeepMap should use is() for final value equality #690

Closed
wants to merge 1 commit into from

Conversation

tgriesser
Copy link
Contributor

Noticed that I was seeing a ton of changes when doing a mergeDeepIn and traced it down to the fact that updateDeepMap not using is and thus ending up with every Date object causing a change. This fixes that, test included.

Also I guess somewhere along the line an old version of Immutable.d.ts got checked in, so that's what all the noise is in the change diffs.

@tgriesser
Copy link
Contributor Author

Ping @leebyron - very small change with very big performance implications

@tgriesser tgriesser changed the title updateInDeepMap using is() for final value equality updateInDeepMap should use is() for final value equality Nov 18, 2015
@leebyron
Copy link
Collaborator

Sorry for missing this! Thanks so much for the fix.

I'll clear up the dts noise first and then get this in

@leebyron
Copy link
Collaborator

Hmm, I actually want to understand this a bit better.

There are cases where we use is() to determine value equality - when not knowing true equality would result in an incorrect state, and there are other cases where we use === to determine cheap equality, where we're optimizing what would otherwise be a correct but more expensive operation.

This is similar to myMap.set() where when setting a new value, it's always correct to return a new Map with the provided value set, and we use === as a very cheap optimization to return the same map.

The reason we don't use is() for the optimization opportunity is that it does a full walk of any data structures provided.

I think this case you're updating is an optimization opportunity rather than a result correctness.

However, I think it's safe to use the is() for the optimization specifically for mergeDeep because mergeDeep will always walk over iterables and only the scalar (or at least non-iterable) leafs will be compared and merged.

I think we should find a way to apply this change only in the condition that you're using mergeDeep

@leebyron leebyron closed this in 7c11674 Dec 16, 2015
@tgriesser
Copy link
Contributor Author

Ah you're right - great solution! 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.

None yet

3 participants