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

fix: Performance issue for TreeSelect component #6951

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sinkersan
Copy link

Fixes #6950
You can read a detailed explanation in the issue.

Here’s how I measured performance for the current version:

selectedNodes() {
  let selectedNodes = [];
  
  if (this.d_value && this.options) {
      let keys = { ...this.d_value };
      
      performance.mark('findSelectedNodesStart');
  
      this.findSelectedNodes(null, keys, selectedNodes);
  
      performance.mark('findSelectedNodesEnd');
  
      const perfResult = performance.measure('findSelectedNodesDuration', 'findSelectedNodesStart', 'findSelectedNodesEnd');
  
      console.log(`findSelectedNodes duration: ${perfResult.duration}`);
  }
  
  return selectedNodes;
        }

And here’s how I measure it for my solution:

nodeMap() {
    const nodeMap = {};

    performance.mark('nodeMapStart');

    this.options?.forEach(node => this.fillNodeMap(node, nodeMap))

    performance.mark('nodeMapEnd');

    const perfResult = performance.measure('nodeMapDuration', 'nodeMapStart', 'nodeMapEnd');

    console.log(`nodeMap duration: ${perfResult.duration}`);

    return nodeMap;
},

In both cases, execution time was captured exactly for the recursive function, so I consider it proof.

Copy link

vercel bot commented Dec 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Updated (UTC)
primevue ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 10:23pm
primevue-v3 ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 10:23pm

@sinkersan
Copy link
Author

sinkersan commented Dec 11, 2024

I’ve also noticed that the current version doubles nodes in the selectedNodes computed property for some reason.

image

My version doesn’t have this behavior.

image

I think this is good. Correct me if I’m wrong.

Still, I think it’s better to use a cached object instead of calculating the data every time the user interacts with the component.

Feel free to provide any feedback.

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

Successfully merging this pull request may close these issues.

TreeSelect: Performance issue in selectionMode="checkbox"
1 participant