Performance issue

Grids for WPF Forum

Posted 14 years ago by SledgeHammer01
Version: 10.1.0521
Avatar
I have a standard tree view control. It contains a tree of items. When I select a tree view item, I display the properties of the item in the property grid using the following code:

            TreeViewItemEx tvi = (TreeViewItemEx)e.NewValue;
            FieldProxy fp = (FieldProxy)tvi.Tag;

            pgFields.Items.Clear();

            PropertyGridCategoryItem ci1 = new PropertyGridCategoryItem();
            ci1.DisplayName = "General";
            pgFields.Items.Add(ci1);

            ci1.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "Name"));
            ci1.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "Description"));
            ci1.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "Cloneable"));
            ci1.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "ReadOnly"));

            PropertyGridCategoryItem ci2 = new PropertyGridCategoryItem();
            ci2.DisplayName = "Scripts";
            pgFields.Items.Add(ci2);

            ci2.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "OnExtract"));
            ci2.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "OnVerify"));
            ci2.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "OnExport"));

            PropertyGridCategoryItem ci3 = new PropertyGridCategoryItem();
            ci3.DisplayName = "Constraints";
            pgFields.Items.Add(ci3);

            _category = ci3;

            IPropertyDataAccessor accessor = new PropertyDescriptorDataAccessor(fp, "FieldType");
            ci3.Accessors.Add(accessor);
            UpdateConstraintsCategory((FieldType)accessor.Value);
UpdateConstraintsCategory() is just a switch that adds 3 more items depending on the type.

Its pretty slow switching tree nodes letting this code execute. Can anything be done to speed it up?

* I do get the errors I mentioned before:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='ActiproSoftware.Windows.Controls.PropertyGrid.TreeListViewItem', AncestorLevel='1''. BindingExpression:Path=IsExpanded; DataItem=null; target element is 'TreeListViewToggleButton' (Name=''); target property is 'IsChecked' (type 'Nullable`1')

* I tried BeginUpdate and EndUpdate, but that didn't do anything.

* If I comment out the 8 or so lines where I add the items, the speed is good.

* If I only add the first 4 items, it is already pretty slow.

* I need to use this vs. SelectedObject because I need to be able to remove / add items dynamically.

[Modified at 04/21/2010 07:36 PM]

Comments (8)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

When you work directly with the Items/ItemsSource, the PropertyGrid works much like a TreeView (as far as when it refreshes the view, builds containers, etc). When you use one of the PropertyGrid specific properties, like SelectedObject(s)/Properties/etc, then you can use BeginUpdate/EndUpdate to batch the changes into a single refresh.

Instead of working with the Items collection, you may want to use ItemsSource. There's no way to "batch" changes to the Items collection. What you can do is create and populate a new List<IDataAccessor>, then once it's completely setup then assign it to ItemsSource. You would also need to set IsItemsSourceAutoUpdated to false.

If this doesn't help, please put together a small sample project that reproduces the issue and email it over to our support address, and then we can take a closer look.


Actipro Software Support

Posted 14 years ago by SledgeHammer01
Avatar
Hi, I have changed my code as follows:


            TreeViewItemEx tvi = (TreeViewItemEx)e.NewValue;
            FieldProxy fp = (FieldProxy)tvi.Tag;

            //pgFields.Items.Clear();

            List<IDataAccessor> list = new List<IDataAccessor>();

            PropertyGridCategoryItem ci1 = new PropertyGridCategoryItem();
            ci1.DisplayName = "General";
            list.Add(ci1);

            ci1.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "Name"));
            ci1.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "Description"));
            ci1.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "Cloneable"));
            ci1.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "ReadOnly"));

            PropertyGridCategoryItem ci2 = new PropertyGridCategoryItem();
            ci2.DisplayName = "Scripts";
            list.Add(ci2);

            ci2.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "OnExtract"));
            ci2.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "OnVerify"));
            ci2.Accessors.Add(new PropertyDescriptorDataAccessor(fp, "OnExport"));

            PropertyGridCategoryItem ci3 = new PropertyGridCategoryItem();
            ci3.DisplayName = "Constraints";
            list.Add(ci3);

            _category = ci3;

            IPropertyDataAccessor accessor = new PropertyDescriptorDataAccessor(fp, "FieldType");
            ci3.Accessors.Add(accessor);
            UpdateConstraintsCategory((FieldType)accessor.Value);

            pgFields.IsItemsSourceAutoUpdated = false;
            pgFields.ItemsSource = list;

Is that what you meant? Just adding the categories to the list and the items to the categories as before?

Unfortunately, I did not see any performance gain at all.
Posted 14 years ago by SledgeHammer01
Avatar
Hi, I have put together a sample app.

This has the performance issue as well as the tons of "System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor,..." errors.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

Thank you for the sample. I tried this on my desktop and a VM, and both updated almost instantaneously. We have seen issues relating to performance that have been resolved by updating your video driver. I'm not sure that's the case here. Can you provide more information about the processor/memory/etc. of the box you are running this on? Did you try it on various boxes?

The binding errors can generally be disregarded, as it's a timing issue in WPF and not really related to our code. We have been able to resolve some of these "warnings" in the past, but not always.

For more information, see http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/f66e32dc-e4d4-4af1-9475-008bb902b932/#a0582b37-eb03-42fb-8eb1-d03bcecd74cd


Actipro Software Support

Posted 14 years ago by SledgeHammer01
Avatar
My hardware setup is:

HP Compaq dc7700 Convertible
Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz
2.39GHz, 3.49GB of RAM
Intel(R) Q965/Q963 Express Chipset Family
Driver Date: 12/12/2008
Driver Version: 6.14.10.5016

My software setup is:

Microsoft Windows XP SP3 fully patched
Visual Studio 2010 RTM
.NET 4.0 RTM
ActiPro build 2010.1

I'm pretty sure I have the latest video drivers as I just upgraded them a few weeks ago. I do realize that the embedded video card is not very high end, but this is a business application, so we aren't going to have dual SLI cards going or anything like that :).

On my machine, I notice the following in the performance:

* if I click on each node moderately / fast in succession, I can usually stay 1 or 2 nodes ahead of what is shown on screen. If I comment out the property grid stuff, its all real time. I can't stay ahead of the screen no matter how fast I click.

* if I select the very top node and hold the down arrow on the keyboard, there is a noticable lag as it goes from node to node. If I comment out the property grid stuff, again, I can hold down the down arrow and blaze through the choices. With the property grid stuff its more like select - pause - select - pause - select - pause, etc.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

I've marked down a TODO item to look into this further. Based on your sample, I believe the issue has to do with the arranging and measuring of the items. This process isn't something that we have alot of control over, atleast not in terms of speeding up. One idea that we have is to reduce the number of visuals used, as that generally speeds up the arrange/measure phase.

The PropertyGrid generally works like a TreeView, when it comes to arrange/measure, but there is definitely alot more going on. As we are not seeing the issue, you may be able to run a performance profile on your sample application to see where the majority of the time is spent. But again, I suspect it's the arrange/measure phases.


Actipro Software Support

Posted 14 years ago by SledgeHammer01
Avatar
Has there been any progress on this issue? We are getting a few complaints on the performance in that area of the GUI :).
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

Sorry, no this has not been investigated any further at this point.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.