-
-
Notifications
You must be signed in to change notification settings - Fork 852
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
[breaking change] implement and default to useStrictShallowCopy, omitting getters #941
Conversation
👷 Deploy request for quizzical-lovelace-dcbd6a pending review.Visit the deploys page to approve it
|
b3f10f2
to
d693e8f
Compare
I didn't read the code yet, but could you include a rationale in the PR description, what are you updating and why is it faster, what does the API look like, in which cases will it break things, etc? |
Pull Request Test Coverage Report for Build 2343830328Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Thank you for your advice. |
@hrsh7th @mweststrate this looks like a great PR to give users (like me) meaningfully better performance with large objects (>1000 keys). Was it closed just for lack of activity? |
It was missing rationale IIRC when it was closed, but now I see it is present, so reopening :) It might take some time to process though due to my own personal circumstances. Apologies upfront! |
I think it makes sense to make this behavior the new default, ship it as separate major version and make the old behavior opt-in using a flag. |
Thank you for your review. Nice to hear that this PR is an acceptable change. I noticed that the test is failing. I will fix it. |
f9cdf8e
to
31e61bf
Compare
Could you approve the GitHub Actions? In my environment, this branch is passed the all tests... I want to re-try GitHub Actions. |
done! |
Thank you! It seems to pass the tests. |
if (canReferNonEnumerableProperty) expect(nextState.foo).toBeTruthy() | ||
if (useStrictShallowCopy) | ||
expect(isEnumerable(nextState, "foo")).toBeFalsy() | ||
if (useStrictShallowCopy) expect(nextState.baz).toBeTruthy() |
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 test is ugly, but after some consideration, I think it should be the spec.
First, I thought that non-enumerable properties should not be visible from drafts when useStrictShallowCopy is false.
However, achieving this behavior requires checking whether the referenced property is non-enumerable, which introduces new overhead.
I'm not confident about the documentation part, but I think the code part is ready for review. |
🎉 This PR is included in version 10.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
Fixes #867
This PR improves the performance when updating the object that contains a large number of entries.
Problem
The current immer takes a long time for creating new object when the draft object has large amount of keys.
From some of the investigation, I found the cause that is
getOwnPropertyDescriptors
(here) .In my computer, the
ownKeys
and its iteration don't take a long time butgetOwnPropertyDescriptors
takes time near the 10ms.I can understand that the
getOwnPropertyDescriptors
is needed. Because immer should copy object's descriptors such as getter/setter/non-enumerable keys.But some of the users doesn't need that strictness, I think.
Solution
Add the ability to opt-out of strict shallow copy implementation for performance reasons.edited
Make the default behavior not strict shallow copy. And add the ability to opt-in to strict shallow copying.
Result
The following results show the benefit of this patch.