-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
[tree view] Should use maps not arrays for selected / expanded #12283
Comments
This line shows that there is indeed an array look up for finding if the item is expanded But firstly Arrays in JavaScript are known to have faster lookup time when they have small length and secondly both in terms of performance and proper type usage you should go with |
An array is easier to handle for the basic use case. IMO In the end it boils down to: Are there real-world use cases where dictionaries make a noticeable difference? |
I was interested in testing this approach out, it seems that it's a great approach. var expanded1 = Array.from(new Array(100000)).map((_, index) => String(index))
console.time('conversion')
var expanded2 = expanded1.reduce((acc, index) => {
acc[index] = true;
return acc;
}, {});
console.timeEnd('conversion')
console.time('array')
expanded1.indexOf('foo')
console.timeEnd('array')
console.time('object')
expanded['foo']
console.timeEnd('object')
It looks like that if we hit a performance issue, we can handle the concern internally, 20 items are enough to convert the data structure to an object and observe an ROI > 1. So I don't think that performance should be a concern from the API standpoint. This makes me think, virtualization support could be pretty neat! |
|
I had similar thoughts on this, I had previously discussed using a Set but decided against it since I did not have an example where I could measure the actual performance impact as @eps1lon suggested. |
We also require virtualization for Tree View. Most of the time, Tree VIew has many items inside. |
@rash2x Could you open a new issue for Virtualization? Thanks |
@oliviertassinari done! #9685 |
Right now selected/expanded are arrays and not maps/dictionaries.
Arrays are linear time lookup. Maps are constant time... O(N) vs O(1)...
For smaller maps it won't matter but for bigger maps performance will be impacted.
Search keywords:
The text was updated successfully, but these errors were encountered: