Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Performance issue

Performance issue

Scheduled Pinned Locked Moved C#
helpwpfwcfdesigndata-structures
11 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DJ245
    wrote on last edited by
    #1

    Hi, I am facing with a performance issue in one of my windowsapplication. I need to create a dialog window for excluding subfolders and files in a particular folder (passed as input). The Exclude dialog must allow the user to select folders and files which he wants to exclude from counting. Currently I am using a tree view and list view (both with checkboxes) for this purpose. Implementation: 1. I bind the tree view with all subfolders on the load time. 2. The list view shows the files and folders of each selected node in the tree. 3. When a node or list item checked or unchecked, all its sub-items has to get checked or unchecked. Issue faced: 1. In case of a large folder (with large no. of Subfolders and files), it takes long time for loading the tree (to bind all these sub-folders and files to tree) 2. If I go for an implementation of binding only two levels to the tree node each time (on load and on node click), issue occurs when I uncheck a node or list item. Only the sub items up to 2 level gets unchecked. 3. Check- Uncheck for large subfolders too takes long time. Can anyone help me out with a solution for this? Even a design change or change in the current implementation can be suggested. Thanks in Advance Praji

    W 1 Reply Last reply
    0
    • D DJ245

      Hi, I am facing with a performance issue in one of my windowsapplication. I need to create a dialog window for excluding subfolders and files in a particular folder (passed as input). The Exclude dialog must allow the user to select folders and files which he wants to exclude from counting. Currently I am using a tree view and list view (both with checkboxes) for this purpose. Implementation: 1. I bind the tree view with all subfolders on the load time. 2. The list view shows the files and folders of each selected node in the tree. 3. When a node or list item checked or unchecked, all its sub-items has to get checked or unchecked. Issue faced: 1. In case of a large folder (with large no. of Subfolders and files), it takes long time for loading the tree (to bind all these sub-folders and files to tree) 2. If I go for an implementation of binding only two levels to the tree node each time (on load and on node click), issue occurs when I uncheck a node or list item. Only the sub items up to 2 level gets unchecked. 3. Check- Uncheck for large subfolders too takes long time. Can anyone help me out with a solution for this? Even a design change or change in the current implementation can be suggested. Thanks in Advance Praji

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      KP_Prajilal wrote:

      In case of a large folder (with large no. of Subfolders and files), it takes long time for loading the tree (to bind all these sub-folders and files to tree)

      You could fill the node when it's opened. Just fill the root and perhaps some child levels in the beginning

      KP_Prajilal wrote:

      If I go for an implementation of binding only two levels to the tree node each time (on load and on node click), issue occurs when I uncheck a node or list item. Only the sub items up to 2 level gets unchecked

      You can either fill the child nodes for the selected node upon selecting but you can also change the logic so that if the child nodes aren't filled, the outer node selection automatically implies to all subfolders even if they are not in the tree. So when working on user's choices (what ever you do with them) you don't expect to find every folder in the tree.

      The need to optimize rises from a bad design.My articles[^]

      D 1 Reply Last reply
      0
      • W Wendelius

        KP_Prajilal wrote:

        In case of a large folder (with large no. of Subfolders and files), it takes long time for loading the tree (to bind all these sub-folders and files to tree)

        You could fill the node when it's opened. Just fill the root and perhaps some child levels in the beginning

        KP_Prajilal wrote:

        If I go for an implementation of binding only two levels to the tree node each time (on load and on node click), issue occurs when I uncheck a node or list item. Only the sub items up to 2 level gets unchecked

        You can either fill the child nodes for the selected node upon selecting but you can also change the logic so that if the child nodes aren't filled, the outer node selection automatically implies to all subfolders even if they are not in the tree. So when working on user's choices (what ever you do with them) you don't expect to find every folder in the tree.

        The need to optimize rises from a bad design.My articles[^]

        D Offline
        D Offline
        DJ245
        wrote on last edited by
        #3

        I want to bind all the sub folders and file of a root folder when selecting it. Could u please give me a sample code?

        W 1 Reply Last reply
        0
        • D DJ245

          I want to bind all the sub folders and file of a root folder when selecting it. Could u please give me a sample code?

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          The idea was that you don't take all the folders to the tree, only the nodes are selected. You can use BeforeExpand[^] event and in that event you fill the folders right under that node (if not already filled). When you perform the operation (whatever it is) you check if the node is present and based on the selection you do the operation. You can use recursion in the operation just check if node is selected and if it is, recurse child nodes if there are any. if there aren't recurse, the folders under that folder and do the operation if the node was selected.

          The need to optimize rises from a bad design.My articles[^]

          D 1 Reply Last reply
          0
          • W Wendelius

            The idea was that you don't take all the folders to the tree, only the nodes are selected. You can use BeforeExpand[^] event and in that event you fill the folders right under that node (if not already filled). When you perform the operation (whatever it is) you check if the node is present and based on the selection you do the operation. You can use recursion in the operation just check if node is selected and if it is, recurse child nodes if there are any. if there aren't recurse, the folders under that folder and do the operation if the node was selected.

            The need to optimize rises from a bad design.My articles[^]

            D Offline
            D Offline
            DJ245
            wrote on last edited by
            #5

            I tried it and got better performance while binding the folders. But when Check/Uncheck a root folder performance is too low(for Check/Uncheck the sub folders). How can i solve this? Thanks in Advance Praji

            W 1 Reply Last reply
            0
            • D DJ245

              I tried it and got better performance while binding the folders. But when Check/Uncheck a root folder performance is too low(for Check/Uncheck the sub folders). How can i solve this? Thanks in Advance Praji

              W Offline
              W Offline
              Wendelius
              wrote on last edited by
              #6

              DJ245 wrote:

              But when Check/Uncheck a root folder performance is too low(for Check/Uncheck the sub folders). How can i solve this?

              Without seeing the code you've made, it's quite impossible to say why it's slow. When the root node is checked, do you for example recursively traverse all of the subnodes and check them also? That would explain why it's slow. Also if that's the case, it depends how you have done it. Can you post the code that is used when checking a node?

              The need to optimize rises from a bad design.My articles[^]

              D 1 Reply Last reply
              0
              • W Wendelius

                DJ245 wrote:

                But when Check/Uncheck a root folder performance is too low(for Check/Uncheck the sub folders). How can i solve this?

                Without seeing the code you've made, it's quite impossible to say why it's slow. When the root node is checked, do you for example recursively traverse all of the subnodes and check them also? That would explain why it's slow. Also if that's the case, it depends how you have done it. Can you post the code that is used when checking a node?

                The need to optimize rises from a bad design.My articles[^]

                D Offline
                D Offline
                DJ245
                wrote on last edited by
                #7

                Code used :

                 #region CheckUncheckChildNodes
                    /// /// This method is used to check/uncheck the subsequent child nodes on checking a node.
                    /// 
                    private void CheckUncheckChildNodes(TreeNode node)
                    {
                        childCheck = true;
                        //if the selected node is checked
                        if (node.Checked == true)
                        {
                            //check if the selected node already present in removedFileList, 
                            //if not add the node to initalFileList (which has the list of selected files and folders)
                            bool isExists = false;
                            for (int index = 0; index < removedFileList.Count; index++)
                            {
                                string name = removedFileList\[index\].ToString().Replace("\\\\\\\\", "\\\\");
                                if (name == node.FullPath)
                                {
                                    isExists = true;
                                    break;
                                }
                            }
                            if (isExists)
                                removedFileList.Remove(node.FullPath);
                
                            //check all the filtered files in the selected node
                            CheckUncheckFilteredFiles(node, node.Checked);
                
                            //check all the sub-nodes of the selected node
                            foreach (TreeNode childNode in node.Nodes)
                            {
                                childNode.Checked = true;
                                CheckUncheckChildNodes(childNode);
                            }
                        }
                        //if the selected node is not checked
                        else
                        {
                            //check if the selected node already present in initalFileList, 
                            //if present, remove the node from initalFileList (which has the list of selected files and folders)                
                
                            bool isExists = false;
                            for (int index = 0; index < removedFileList.Count; index++)
                            {
                                string name = removedFileList\[index\].ToString().Replace("\\\\\\\\", "\\\\");
                                if (name == node.FullPath)
                                {
                                    isExists = true;
                                    break;
                                }
                            }
                            if (!isExists)
                                removedFileList.Add(node.FullPath);
                
                            //uncheck all the filtered files in the selected node
                            CheckUncheckFilteredFiles(node, node.Checked);
                            //uncheck all the sub-nodes of the selected node
                            forea
                
                W 1 Reply Last reply
                0
                • D DJ245

                  Code used :

                   #region CheckUncheckChildNodes
                      /// /// This method is used to check/uncheck the subsequent child nodes on checking a node.
                      /// 
                      private void CheckUncheckChildNodes(TreeNode node)
                      {
                          childCheck = true;
                          //if the selected node is checked
                          if (node.Checked == true)
                          {
                              //check if the selected node already present in removedFileList, 
                              //if not add the node to initalFileList (which has the list of selected files and folders)
                              bool isExists = false;
                              for (int index = 0; index < removedFileList.Count; index++)
                              {
                                  string name = removedFileList\[index\].ToString().Replace("\\\\\\\\", "\\\\");
                                  if (name == node.FullPath)
                                  {
                                      isExists = true;
                                      break;
                                  }
                              }
                              if (isExists)
                                  removedFileList.Remove(node.FullPath);
                  
                              //check all the filtered files in the selected node
                              CheckUncheckFilteredFiles(node, node.Checked);
                  
                              //check all the sub-nodes of the selected node
                              foreach (TreeNode childNode in node.Nodes)
                              {
                                  childNode.Checked = true;
                                  CheckUncheckChildNodes(childNode);
                              }
                          }
                          //if the selected node is not checked
                          else
                          {
                              //check if the selected node already present in initalFileList, 
                              //if present, remove the node from initalFileList (which has the list of selected files and folders)                
                  
                              bool isExists = false;
                              for (int index = 0; index < removedFileList.Count; index++)
                              {
                                  string name = removedFileList\[index\].ToString().Replace("\\\\\\\\", "\\\\");
                                  if (name == node.FullPath)
                                  {
                                      isExists = true;
                                      break;
                                  }
                              }
                              if (!isExists)
                                  removedFileList.Add(node.FullPath);
                  
                              //uncheck all the filtered files in the selected node
                              CheckUncheckFilteredFiles(node, node.Checked);
                              //uncheck all the sub-nodes of the selected node
                              forea
                  
                  W Offline
                  W Offline
                  Wendelius
                  wrote on last edited by
                  #8

                  Lets start with the CheckUncheckChildNodes method. You have an array removedFileList. Instead of using an array and always looping through it, use for example HashTable. Something like this when you add new files to the list (or whatever code you use when you add to the array):

                  private System.Collections.HashTable removedFileList = new System.Collections.HashTable();
                  ...
                  // when adding to HashTable:
                  removedFileList.Add(node.FullPath, "");

                  Now when you have the CheckUncheckChildNodes method, you could modify your code to this:

                  ...
                  //check if the selected node already present in removedFileList,
                  //if not add the node to initalFileList (which has the list of selected files and folders)
                  if (removedFileList.ContainsKey(node.FullPath))
                  removedFileList.Remove(node.FullPath);

                  //check all the filtered files in the selected node
                  CheckUncheckFilteredFiles(node, node.Checked);
                  ...

                  The same applies to the else section if the selected node is not checked. That would speed up the execution and use less code. The same idea can be used in CheckUncheckFilteredFiles

                  The need to optimize rises from a bad design.My articles[^]

                  D 1 Reply Last reply
                  0
                  • W Wendelius

                    Lets start with the CheckUncheckChildNodes method. You have an array removedFileList. Instead of using an array and always looping through it, use for example HashTable. Something like this when you add new files to the list (or whatever code you use when you add to the array):

                    private System.Collections.HashTable removedFileList = new System.Collections.HashTable();
                    ...
                    // when adding to HashTable:
                    removedFileList.Add(node.FullPath, "");

                    Now when you have the CheckUncheckChildNodes method, you could modify your code to this:

                    ...
                    //check if the selected node already present in removedFileList,
                    //if not add the node to initalFileList (which has the list of selected files and folders)
                    if (removedFileList.ContainsKey(node.FullPath))
                    removedFileList.Remove(node.FullPath);

                    //check all the filtered files in the selected node
                    CheckUncheckFilteredFiles(node, node.Checked);
                    ...

                    The same applies to the else section if the selected node is not checked. That would speed up the execution and use less code. The same idea can be used in CheckUncheckFilteredFiles

                    The need to optimize rises from a bad design.My articles[^]

                    D Offline
                    D Offline
                    DJ245
                    wrote on last edited by
                    #9

                    Changed my code . But no improvement. Performance is same as previous.

                    W 1 Reply Last reply
                    0
                    • D DJ245

                      Changed my code . But no improvement. Performance is same as previous.

                      W Offline
                      W Offline
                      Wendelius
                      wrote on last edited by
                      #10

                      One question is that do you still have all the files and directories initially in the tree view. I'm asking this because both listview and treeview can handle few thousand rows. After that the performance degrades radically. The next step is that is the CheckUncheckChildNodes method slow or the CheckUncheckFilteredFiles method? I would guess that it's CheckUncheckFilteredFiles. You can try this by commenting out the call to CheckUncheckFilteredFiles from CheckUncheckFilteredFiles. I figured out that you're listing both files and folders in the same treeview but you exclude some files based on their extension or is it vice versa, if the user has selected a parser, do you show only files with certain extension? If you show only certain extensions, use serchpattern on GetFiles Then you also show an icon based on the file. However did I understand correctly that you have a separate icon for every file??

                      subNode.ImageIndex = sysIcons.GetIconIndex(fil.FullName)

                      Also I don't seem to find that you are clearing subnodes anywhere so if the directory is read twice, won't you have duplicate rows on the tree? One way to enhance the performance is to use a tree for folders only and a list view for files, same as Windows Explorer. By separating them you wouldn't have so many items in the tree. Also, what's the whole idea. You have a form where you have a combobox? for parser selection. After selecting the parser, user can select what files are parsed? All the files that are selected are parsed and if a node is parsed then every file in that node and it's subnodes are parsed? Was that even close?

                      The need to optimize rises from a bad design.My articles[^]

                      D 1 Reply Last reply
                      0
                      • W Wendelius

                        One question is that do you still have all the files and directories initially in the tree view. I'm asking this because both listview and treeview can handle few thousand rows. After that the performance degrades radically. The next step is that is the CheckUncheckChildNodes method slow or the CheckUncheckFilteredFiles method? I would guess that it's CheckUncheckFilteredFiles. You can try this by commenting out the call to CheckUncheckFilteredFiles from CheckUncheckFilteredFiles. I figured out that you're listing both files and folders in the same treeview but you exclude some files based on their extension or is it vice versa, if the user has selected a parser, do you show only files with certain extension? If you show only certain extensions, use serchpattern on GetFiles Then you also show an icon based on the file. However did I understand correctly that you have a separate icon for every file??

                        subNode.ImageIndex = sysIcons.GetIconIndex(fil.FullName)

                        Also I don't seem to find that you are clearing subnodes anywhere so if the directory is read twice, won't you have duplicate rows on the tree? One way to enhance the performance is to use a tree for folders only and a list view for files, same as Windows Explorer. By separating them you wouldn't have so many items in the tree. Also, what's the whole idea. You have a form where you have a combobox? for parser selection. After selecting the parser, user can select what files are parsed? All the files that are selected are parsed and if a node is parsed then every file in that node and it's subnodes are parsed? Was that even close?

                        The need to optimize rises from a bad design.My articles[^]

                        D Offline
                        D Offline
                        DJ245
                        wrote on last edited by
                        #11

                        I used this to count the LOC of a whole project. For example my project folder contains around 250 folders and 25000 files. A tree view is used to list out the folders with check boxes and a list view to display all the files under selected folder. Both the two functions are slow. Main form contains a combo box for parser selection and another combo box for selecting folder.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups