This is a migrated thread and some comments may be shown as answers.

RemoveLink method is Low efficiency

4 Answers 37 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
rui
Top achievements
Rank 1
rui asked on 05 Jul 2017, 11:15 AM

when I  batch delete links,  the number is 2000, I use removelink method to remove the link from UI, but the efficiency is very low, the time is 67 seconds,  if do not call the method the time is 2 seconds

why the removelink  method is so low efficiency, and is any solution the raise batch delete links efficiency?

 

thank you !

4 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 10 Jul 2017, 07:55 AM
Hello Rui,

I tested several approaches for clearing the links in the diagram including the RemoveLink() method, but I wasn't able to see any change in the time spent for the operation. It is around 2-3 seconds on my side. Can you take a look at the attached project and let me know if I am missing something?

Currently, the RadDiagram control doesn't support batch delete. Keep in mind that removing 2000 UI elements from the visual tree is a heavy operation for the the WPF framework.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
rui
Top achievements
Rank 1
answered on 11 Jul 2017, 08:42 AM

thank you 

 1.  when select the links and delete,  the spend time is about 96 second, but when did not select and delele  the time is 6 second,  so I can set Diagram's SelectedItem to null to improve the efficienty,Is there any room for improvement

2,In my business scenario  the link is belongs to different node, when i create 4000 nodes and 2000 link, the load and render time is 30 second,  is any method to improve it 

my test code :

 private void Button_Click(object sender, RoutedEventArgs e)
        {
            var source = this.DataContext as GraphSource;
            diagram.SelectAll();//if delete this code the spend time is 6 second
            var dd = DateTime.Now;
            while (source.InternalLinks.Count > 0)
            {
                var link = source.InternalLinks[source.InternalLinks.Count - 1];
                source.RemoveLink(link);
            }
            var test = (DateTime.Now - dd).TotalSeconds; //96  second
        }

        private void LoadData_Click(object sender, RoutedEventArgs e)
        {
            var dd = DateTime.Now;
           
            var source = new GraphSource();
           
            for (int i = 0; i < 2000; i++)
            {
                var node1 = new Node() { Content = "Shape 1", Position = new Point(100, 100) };
                var node2 = new Node() { Content = "Shape 2", Position = new Point(400, 100) };
                source.AddNode(node1);
                source.AddNode(node2);
                source.AddLink(new Link() { Source = node1, Target = node2 });
            }

            this.DataContext = source;
            var test = (DateTime.Now - dd).TotalSeconds; //the time is about 9 second  and UI render is about  20 second
        }

0
Accepted
Martin Ivanov
Telerik team
answered on 14 Jul 2017, 06:30 AM
Hello Rui,

Thank you for the additional information. I used it to update my test project. 

I wasn't able to reproduce the 96 seconds delay, but I guess this differs by the machine where the code is executed. However, I can agree that the performance is not very optimal and there is a difference between delete without and delete with selection. Well, this is kinda expected because the selection in the diagram is coupled with additional code and calculations to be executed which in such heavy scenario leads to a performance hit.

In general, rendering and manipulation 6000 complex UI elements as the shapes and connections is heavy operation. To improve this a bit the diagram control supports type of UI virtualization which collapses the shapes outside of the viewport. However, this feature is not effective on loading of the diagram because even virtualized it creates and work with all the required shapes. 

I cannot suggest you a unified method to improve the performance, but you could try the following tips.
  • Modify the template of the connection and shape elements (RadDiagramShape, RadDiagramConnection). You can revise the templates and see if you can strip down the parts that you don't need. Less UI elements, less rendering time.
  • If you are running the diagram on a touch device (monitor, table, etc.) you can disable the automation peers.
  • Show as less diagram items in the viewport as possible. Additionally, you can implement custom data virtualization. To do this you can subscribe for the diagram's PositionChanged event which is fired when the viewport changes. In the event handler add the nodes which positions are in the viewport and remove the others.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
rui
Top achievements
Rank 1
answered on 14 Jul 2017, 07:05 AM

Hi Martin,

Thanks for your help

We have determined the improve plan,  we will  try to reduce the node in the viewport

Tags
Diagram
Asked by
rui
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
rui
Top achievements
Rank 1
Share this question
or