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

[Request] Don't traverse frozen objects #3147

Closed
hgascoigne opened this issue Jun 24, 2016 · 0 comments
Closed

[Request] Don't traverse frozen objects #3147

hgascoigne opened this issue Jun 24, 2016 · 0 comments

Comments

@hgascoigne
Copy link

I have an application that stores a large number of plain objects in an array. Using Object.freeze I can prevent Vue from making the items in the array reactive, but whenever I replace the array with a new frozen array, Vue tries to traverse all of the items anyway.

Since the array itself is reactive (as a property on its parent object), I believe the traversal is caused by the following in traverse():

if (isA) {
   i = val.length;
   while (i--) traverse(val[i], seen);
}

I've been able to fix the problem by adding this line:

if (!Object.isExtensible(val)) return

Immediately inside of:

if (isA || isO) {
    if (!Object.isExtensible(val)) return // Addition
    if (val.__ob__) {
      var depId = val.__ob__.dep.id;

 ...

Comparing JS profiles with/without that line gives a dramatic increase in speed for me. Since it's frozen, there won't be any getters in there anyway so why look? Instead of maintaining my own fork, I wanted to see if there was a reason this shouldn't be added into core.

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

1 participant