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

performance: current creates new copies of the objects where unnecessary #47

Closed
francescotescari opened this issue Jul 22, 2024 · 3 comments

Comments

@francescotescari
Copy link
Contributor

current creates a copy of nested objects, even when such objects are not draft.
Consider the following example:

  const obj = { k: 42 };
  const original = { x: { y: { z: [obj] }}}
  const yReplace = { z: [obj] } ;

  // with create
  const withCreate = create(original, draft => {
    draft.x.y = yReplace;
  });
  console.log(withCreate.x.y === yReplace) // prints true
  console.log(withCreate.x.y.z[0] === obj) // prints true

  // with draft + current
  const [draft] = create(original);
  draft.x.y = yReplace;
  const withDraft = current(draft);
  console.log(withDraft.x.y === yReplace) // prints false
  console.log(withDraft.x.y.z[0] === obj) // prints false! DEEP COPY???

I would expect the draft + current to behave like the create option, returning the new object, but currently actually performs a deep copy instead. This has a big negative impact on the performance of current

@unadlib
Copy link
Owner

unadlib commented Jul 23, 2024

Thank you for submitting this issue and PR.

@unadlib
Copy link
Owner

unadlib commented Jul 23, 2024

Perhaps tomorrow I will do some minor refactoring and release a new version.

@unadlib
Copy link
Owner

unadlib commented Jul 24, 2024

hi @francescotescari, I have released Mutative v1.0.7. Feel free to use it.

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

No branches or pull requests

2 participants