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

TreeSelect: Performance issue in selectionMode="checkbox" #6950

Open
sinkersan opened this issue Dec 11, 2024 · 0 comments · May be fixed by #6951
Open

TreeSelect: Performance issue in selectionMode="checkbox" #6950

sinkersan opened this issue Dec 11, 2024 · 0 comments · May be fixed by #6951
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team
Milestone

Comments

@sinkersan
Copy link

Describe the bug

Hello!

I noticed a performance issue with the TreeSelect component when using a large dataset (more than 10K items). This issue occurs every time the user clicks on a node in the tree.

In the screenshot below, you can see the execution time on my machine. In the provided reproduction example, you will find the largeData.json file inside the src folder. This dataset was built based on real-world data from my project.

I investigated the cause of the issue and found that it occurs because of the findSelectedNodes function in the TreeSelect.vue component.

image

This function goes through the whole tree every time the modelValue is changed.

I fixed this issue and will prepare a pull request a bit later.

My solution is based on the strategy of building a cached key-value object where the key is node.key and the value is the node itself.
This object can be used inside the selectedNodes computed property, so no recursion is needed anymore every time when user select node.

Here is a performance comparison between my solution and the original one.
Performance was measured using the performance.mark and performance.measure APIs.
nodeMap is the name of my solution, and findSelectedNodes refers to the execution performance of the findSelectedNodes function.

screenshot 2024-12-12

Reproducer

https://stackblitz.com/edit/primevue-4-vite-issue-template-fiy3wg4z?file=src%2FApp.vue

PrimeVue version

4.2.4

Vue version

3.x

Language

TypeScript

Build / Runtime

Vite

Browser(s)

Chrome 131.0.6778.108

Steps to reproduce the behavior

  1. Open demo: https://stackblitz.com/edit/primevue-4-vite-issue-template-fiy3wg4z?file=src%2FApp.vue
  2. Open select
  3. Choose 1st option.

Expected behavior

No noticeable browser freeze every time when node was selected with large amount of children's.

@sinkersan sinkersan added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 11, 2024
sinkersan added a commit to sinkersan/primevue that referenced this issue Dec 11, 2024
sinkersan added a commit to sinkersan/primevue that referenced this issue Dec 11, 2024
@sinkersan sinkersan linked a pull request Dec 11, 2024 that will close this issue
@tugcekucukoglu tugcekucukoglu added Status: Pending Review Issue or pull request is being reviewed by Core Team and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Dec 12, 2024
@tugcekucukoglu tugcekucukoglu added this to the 4.3.0 milestone Dec 12, 2024
@github-project-automation github-project-automation bot moved this to Review in PrimeVue Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team
Projects
Status: Review
Development

Successfully merging a pull request may close this issue.

2 participants