Skip to content

fix: frozen afterward with targetCache #71

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

Closed

Conversation

StepanDyubin
Copy link

Resolves #70

Copy link

codesandbox-ci bot commented Jul 18, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@StepanDyubin StepanDyubin force-pushed the fix/frozen-with-target-cache branch from 57aef8b to f7cdc5d Compare July 18, 2024 11:38
Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, but I don't think this is acceptable as-is.

We need to prove needsToCopyTargetObject isn't costly.
Even if we proved it (which we probably could), it would be still more performant without it, so if we care the performance, we should keep the current algorithm.

(We might be able to remove storing target in the target cache though.)

Comment on lines -212 to -213
const target = getOriginalObject(obj);
if (needsToCopyTargetObject(target)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, previously, we can avoid these computations with the target cache.
I think getOriginalObject is fairly fast, but needsToCopyTargetObject has a loop.

So, there's a performance drawback. Since the target cache is introduced to improve the performance in Valtio, it has to be considered.

Comment on lines +214 to +215
const targetAndCopied =
targetCache && (targetCache as TargetCache<typeof obj>).get(obj);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this usage, we don't need to store the target in the cache.

targetAndCopied = [target, copyTargetObject(target)];

const target = getOriginalObject(obj);
let copiedTarget;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let copiedTarget;
let copiedTarget: typeof target | undefined;

@dai-shi
Copy link
Owner

dai-shi commented Sep 27, 2024

Closing as stale.

@dai-shi dai-shi closed this Sep 27, 2024
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

Successfully merging this pull request may close these issues.

Error when call createProxy twice with the same but frozen object using targetCache
2 participants