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
When adding n values to multi, avoiding looping over them n times #2111
Conversation
Currently, every time you call $input.select2('val', array), the setVal() function is called for every array entry, and setVal() loops over the entire array of values to ensure uniqueness. When the number of values being set is fairly large (on the order of hundreds), this has a dramatic impact on rendering performance. This commit adds a new internal method, setUniqueVal(), to call when a value array is already known to be unique.
'Self' is undefined in scope, just use 'this'
Once before updateSelection is called, once from within updateSelection.
See bugfix commits on this branch. I've had a hard time getting this logic exactly right because there's a lot of redundancy... as of the 3.4.5 release, a typical |
I feel like this isn't needed, as long as the value is always set after |
@kevin-brown Can you explain the close? The fact that |
FYI this performance bottleneck is still an issue as of 3.4.8. |
I've been using this patch in production for several weeks and it has been performing admirably, I'd love to have it (or a similar fix) merged into main so that we don't have to maintain a fork. |
I'm going to reopen this until I can figure a few things out with this. The main ticket for performance-related problems is https://github.com/ivaynberg/select2/issues/781. I'd rather not introduce a new For version 4.0, I believe this issue will be fixed as the logic for setting the values is being changed. |
Glad to hear it, Kevin. Thanks for the update. |
👍 |
https://github.com/ivaynberg/select2/pull/2848 just came in that addresses the core issue. |
@ivaynberg Currently, every time you call
$input.select2('val', array)
, thesetVal()
function is called for every array entry, andsetVal()
loops over the entire array of values to ensure uniqueness. When the number of values being set is fairly large (on the order of hundreds), this has a dramatic impact on rendering performance.This commit adds a new internal method,
setUniqueVal()
, to call when a value array is already known to be unique (as is the case when the call originates fromupdateSelection
).