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

PropagateSelected becoming slow when adding lot's of items to a dropdown in multiple batches #2929

Closed
koenvd opened this issue Jul 1, 2024 · 1 comment · Fixed by #2930
Closed

Comments

@koenvd
Copy link
Contributor

koenvd commented Jul 1, 2024

Description

When adding items to a dropdown in mulitple batches the propagateSelected method takes considerable time to run and becomes slower with a higher number of items.

To reproduce create a dropdown and add items to the dropdown in batches. Amount of items something like 100, 200, 300, ... When you check the performance you will notice the propagateSelected taking more and more time to execute. The reason for this is that the propagateSelected method does a loop for every item in the oldItems list over the complete list of the newItems which makes this a O(n^2) algorithm.

There are different ways to improve this:

  • Only match selected items would solve my use case since typically the amount of selected items is a lot lower than the total amount of items.
  • Ideally we would like to do a fast lookup in a Dictionary based on a lookup key (eg the stringified object). But this doesn't look straightforward because matching items is currently being done on a substring of the stringified object. However I don't get why this is done. Maybe someone can explain the reasoning of this? If we could drop this substring requirement a very fast lookup in a Dictionary would become possible.

Carbon Design System: 5.26.0

@koenvd koenvd changed the title PropagateSelected being slow when adding lot's items to a dropdown in multiple batches PropagateSelected being slow when adding lot's of items to a dropdown in multiple batches Jul 1, 2024
@koenvd koenvd changed the title PropagateSelected being slow when adding lot's of items to a dropdown in multiple batches PropagateSelected becoming slow when adding lot's of items to a dropdown in multiple batches Jul 1, 2024
koenvd added a commit to koenvd/carbon-components-angular that referenced this issue Jul 1, 2024
zvonimirfras added a commit that referenced this issue Jul 16, 2024
…cted

fix: Optimize propagateSelected by limiting matching items to the selected ones (#2929)
Copy link

🎉 This issue has been resolved in version 5.28.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant