Tree Node Rename Performance Problem

S

Saradhi

Hi All,
Here I am facing a performance problem with the TreeView Node renaming.

I am displaying a hierarchy Data in a treeview in my Windows C# Application.
My tree view represents an hierarchical view of Parent Nodes and projects where in a projectnode can be added to any ParentNode and hence we may have a project node added to 100 Parent nodes.

In this one, I have an operation of Renaming a Project Node. So whenever I am doing the operation of renaimg a particular Project Node, I need to rename all the instances of the particular node in the whole Tree View.

So each Tree Node is attached a tag ProjectNode
For this one, I am having a collection of ProjectNode and whenever a project node is renamed, I am calling the rename function of ProjectNode which in turn renames the name of the ProjectNode and then throws an event which will be captured again in the Tree View.
In this Event handler, I am searching the whole Tree view by parsing each and every node and renaming it if it matches wiht the ProjectNode.

This operation is taking a long time and causing an performance issue.

Is there any other alternative Dersign pattern aavilable to solve my problem?

-SARADHI
 
A

Anders Borum

Hello!

First of all - are you persisting changes to the datastore (DB) for each and
every node? If this is the case, the wrapping all the changes in a single
Sql statement (embedded within a Sql transaction) could dramatically
increase the performance of your application.

It all depends on what you're doing .. or need to do. Iterating recursively
on a tree structure shouldn't cause a performance issue, unless we're
talking a very large amount of nodes. How many nodes are affected by a
rename operation?
In this one, I have an operation of Renaming a Project Node. So whenever I am doing
the operation of renaimg a particular Project Node, I need to rename all the instances
of the particular node in the whole Tree View.

Another thing .. you write you're updating all instances of a node in the
tree. Why is this necessary? When adding a node to the tree (i.e. adding a
project node to a parent node), you should only be adding a reference to the
node, not a copy of the node itself (causing redundance and perhaps why you
needed to introduce the event behaviour in the first place).
In this Event handler, I am searching the whole Tree view by parsing each and every
node and renaming it if it matches wiht the ProjectNode.

Definately not a good idea. Please see below .. (for instance: think of an
outside hashtable that contains your Project nodes. The tree nodes point to
these unique instances - use a hashtable if you need a single storage for
fast access of each node)

Parent Node
Project Node A (a reference that points to instance A)
Project Node A (a reference that points to instance A)
Project Node A (a reference that points to instance A)

... instead of ..

Parent Node
Project Node A (instance data)
Project Node A (instance data)
Project Node A (instance data)

More info needed.
 
S

Saradhi

Hi anders borum,

I think you misunderstood my points.
I have two objects here ProjectNode , my business obejct and TreeNode a TreeNode of the TreeView in C#.

Whenever I add a ProjectNode to a parentNode, I am creating a TreeNode and attaching a ProjectNode Object as a tag to that one. So wherever this TreeNode is added to the TreeView, the same ProjectNode will be added as a tag.

So Now whenver I renames the TreeNode in the treview AfterSelect event, I am calling the Rename method of the Corresponding ProjectNode Business object and it first renames the Name in the ProjectNode and then fires an event which will be captured in the TreeView. So in turn, the Rename operation will be done only once in the ProjectNode. But since this Project Node is attached as a tag to a lot of TreeNodes, I am parsing through the Whole TReeView and Renaming them in the Display of the TreeView. This Rename operation is nothing to do with the DB operation which is already finished. This renaming of the all the TreeNodes in the TreeView is necessary because you need to show the changes in the ProjectNode business change graphically in the Entire TreeView.

The problem is that the entire TreeView is getting refreshed unnecessarly even if I have to rename only 5 to 6 tree nodes. Since my hierarchy treeview consists of minimum 5000 Nodes, this refreshing operation looks uglier.

Hope you understood my point here.

With Regards,
-SARADHI

Hello!

First of all - are you persisting changes to the datastore (DB) for each and
every node? If this is the case, the wrapping all the changes in a single
Sql statement (embedded within a Sql transaction) could dramatically
increase the performance of your application.

It all depends on what you're doing .. or need to do. Iterating recursively
on a tree structure shouldn't cause a performance issue, unless we're
talking a very large amount of nodes. How many nodes are affected by a
rename operation?
In this one, I have an operation of Renaming a Project Node. So whenever I am doing
the operation of renaimg a particular Project Node, I need to rename all the instances
of the particular node in the whole Tree View.

Another thing .. you write you're updating all instances of a node in the
tree. Why is this necessary? When adding a node to the tree (i.e. adding a
project node to a parent node), you should only be adding a reference to the
node, not a copy of the node itself (causing redundance and perhaps why you
needed to introduce the event behaviour in the first place).
In this Event handler, I am searching the whole Tree view by parsing each and every
node and renaming it if it matches wiht the ProjectNode.

Definately not a good idea. Please see below .. (for instance: think of an
outside hashtable that contains your Project nodes. The tree nodes point to
these unique instances - use a hashtable if you need a single storage for
fast access of each node)

Parent Node
Project Node A (a reference that points to instance A)
Project Node A (a reference that points to instance A)
Project Node A (a reference that points to instance A)

.. instead of ..

Parent Node
Project Node A (instance data)
Project Node A (instance data)
Project Node A (instance data)

More info needed.
 
A

Anders Borum

The problem is that the entire TreeView is getting refreshed unnecessarly
even if I have
to rename only 5 to 6 tree nodes. Since my hierarchy treeview consists of minimum 5000
Nodes, this refreshing operation looks uglier.

I think I'm with you (..). Instead of going through the entire TreeView
whenever a ProjectNode is added, I would create an index on the ProjectNode
with a list of the TreeNodes that this ProjectNode has been added to.

This should shorted the time required to update the tree. Going through each
and every TreeNode is not a good idea as the time required is proportional
to the number of nodes in the tree (which gets worse and worse as the tree
grows, regardless of the ProjectNode being added to 1 or N tree nodes).

Hopefully this will get you started in the right direction..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top