-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
v-model is slow (hangs) when used on a big select[multiple] element #10014
Comments
And a similar test using @change event instead of v-model vue-select-change.mov |
To a degree, that's expected. We need to set the selected prop on each affected This is essentially a controlled input, where the component always controls which options are selected. Your (totally valid) workaround only uses the @change event, which 1) doesn't cause a re-render and 2) thereby skips the work of re-applying the We might have some room for optimization here, but to a degree v-model will always be inherently be slower than an uncontrolled select due to the additional work it does. |
@LinusBorg I agree, but I think this could be optimized to the extent that it becomes unnoticeable. I believe the slowness here is caused by a slow array search in the v-model implementation. Here's an example where I've attempted to replicate the behavior of v-model, maintaining the original value type and updating the 'selected' attribute for each option. I could optimize it even further, but this is just an example to demonstrate how fast this can be, despite looping over all options. |
using a Set would indeed be more performant, but it doesn't cover all use cases, unfortunately. We currently use a <option :value="{ size: 'small' }"></option>
<option :value="{ size: 'medium' }"></option>
<option :value="{ size: 'large' }"></option> an implementation with We could, in theory, think about a modifier for some kine of "performance" ( But then again: Should we optimize for selects with lists so large that they are unusable anyway? Edit: Looking at our implementation again, there could be away to use a fast path with a Set automatically for primitive values ... |
Appreciate the input @LinusBorg. I actually forgot v-model supports objects as a value. A different strategy could be using a Set to track the indexes of selected options, rather than their values. Not sure about the inline-defined objects though, since I'm not aware of a way to access their value. |
Vue version
3.4.5
Link to minimal reproduction
https://play.vuejs.org/#eNqNUk1v2zAM/SuCLt2Axg6W9eKlQbehh+2wDetuVQ+ZzcRq9QWJdlIY/u+jpCX1sqLoTSQfHx+fOPCPzhV9B7ziy1B76ZAFwM6thJHaWY9sYB42bGQbbzU7I+iZMMLU1oQIVVAjNOwygt7c3r0VZllmHmKgAEE7tUagiLFlxrN+pm0D6lLwA4HgTHcKpVMZSVjrUFpD2I31hJRMGvbuYj6fE7bq16qDmI3BAzzm52oY5Dguy9yaR5Z5RFJDYSP71c3foRUbhqcVYmOsxg0mqikM+JhkZejtQegdGyLlTjbYVmwxn7v9h5hoQW5brBhpTZkxeZI4+DnHQNZt5La4D9aQ64lD8NpqJxX470l6EJzEZSMEXytld19TDn0H54d83UL98Ez+PuxjTvAfHgL4HgQ/1nDtt4C5fH3zDfb0PhbpVzpF6BeKPyFY1UWNGfapMw3JnuCS2i/pdqTZ/grXewQTDktFoRE5JrzgdE+fX1j9Se6iWKQ+8pNczLc502t34mMu/EtCM7LYFtGFqizrxlAbXaDsfWEAS+N0eUWw0ncGpYZZY/XVonhfXNBJBJymCwh69tvbHTlLJJPFY3+y2888mAZ8tOV1Y0/apqNPSv+NP5oy/gHIRUlh
Steps to reproduce
What is expected?
Quick v-model update
What is actually happening?
A very noticeable hang
vue-select-hangs.mov
System Info
No response
Any additional comments?
I'm not just testing performance, I'm actually using this in production, for reasons I won't get into.
I should mention that managing the state manually (e.g. using @change) is fast.
The text was updated successfully, but these errors were encountered: