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

The input box is stucking with follow scenario #3541

Open
BertieGo opened this issue Apr 5, 2021 · 4 comments
Open

The input box is stucking with follow scenario #3541

BertieGo opened this issue Apr 5, 2021 · 4 comments
Labels
has workaround A workaround has been found to avoid the problem scope: reactivity ✨ feature request New feature or request

Comments

@BertieGo
Copy link

BertieGo commented Apr 5, 2021

Version

3.0.11

Reproduction link

SFC Playground

https://codesandbox.io/s/jovial-cohen-docbu?file=/src/App.vue (readonly)

Steps to reproduce

Just open link is fine

What is expected?

Expect the input box in a timely response when I input

What is actually happening?

The input box stucking


The scenario code like this:


template:
<h2>{{ arr[0] }}</h2>
<input type="text" @keyup="keyup">

script:
reactive => arr: [...Array(100000).keys()]

keyup => arr.unshift(Math.random())

ps: BTW,vue2 doesn't appear this problem。

@HcySunYang
Copy link
Member

As a workaround, you can create a new array instead of modifying the original array:

const keyup = () => {
  const newArr = state.arr.slice()
  newArr.unshift(Math.random())
  state.arr = newArr
}

@HcySunYang HcySunYang added the has workaround A workaround has been found to avoid the problem label Apr 6, 2021
@HcySunYang
Copy link
Member

Hint.

When calling unshift/shift/splice, etc., these methods will manipulate the original array. In the worst case, that will call the set trap for the array integer key n times, n represents the number of array elements, which is a time-consuming operation.

@BertieGo
Copy link
Author

BertieGo commented Apr 7, 2021

Hint.

When calling unshift/shift/splice, etc., these methods will manipulate the original array. In the worst case, that will call the set trap for the array integer key n times, n represents the number of array elements, which is a time-consuming operation.

Thanks for your comment, this issue brings me to a deeper question, which is that if Vue2 doesn't monitoring array elements because unshift/shift/splice & for triggers defindProperty method: getter/setter and leads to high performance cost, then Vue3 Proxy seems to have the same problem. Is there any idea to solve this problem?

@HcySunYang
Copy link
Member

Calling shift/unshift...on the proxy array is an extremely performance-consuming operation https://jsbench.me/n5knjtmjlz/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has workaround A workaround has been found to avoid the problem scope: reactivity ✨ feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants