Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
High cost to re-bind XamDataGrid.DataSource in some scenarios
posted

We are seeing that in some scenarios there is a much higher cost to re-bind the DataSource of a XamDataGrid.  It seems, based on profiling traces, that all the time is spent in RemoveLogical/VisualChild downstack from GridViewPanelFlat+GenerationCache.Dispose() and AddLogicalChild downstack from GridViewPanelFlat+GenerationCache.GenerateAllRecords().

We're trying to get a reduced repro of this to share but we have yet to achieve it.  In our full solution it seems that these hotpaths are always being hit when re-binding DataSource.  However, in the simplest fully independent scenario of a XamDataGrid and a button to effect a re-bind of the DataSource we do not see these hotpaths being hit at all.  I am able to get a rather minimal repro of the Dispose side of things, so I'll focus on that for now.

The further discussion is based off of a sample I will attach.  In the sample there is a window with a XamDockManager and a Button.  Clicking the Button will add a view with a XamDataGrid to the DocumentContentHost of the XamDockManager. The view also has a button to refresh the data.

Attached is a screen snip illustrating the hotpaths in Dispose.  The view (SampleDataView) hooks the XamDataGrid.Loaded so that it can further hook the RecyclingItemsControl.ContainerDiscarded, you can set a breakpoint in this event handler to see when containers are being discarded and therefore when we hit the hotpath.

If you simply click the "Load Data" button once and then continually click the "Reload" for the single XamDataGrid you will see that the breakpoint is never hit.  This is as we would expect.

If you click "Load Data" more than once and you re-dock the tabgroups a couple times and then click "Reload" then the first reload for each will hit the hotpath.  All extant containers will be discarded.  From our viewpoint this shouldn't be happening, it really shouldn't be any different from the previous case. 

There seems to be something that has changed internal state for the XamDatGrid and related components that causes it to discard all the containers.  This is the minimal case we have found thus far that hits the hotpath.  Note, however, that in our full solution the hotpath is *always* hit, not just after a re-dock operation.

Of additional note, you can see the virtualization settings in the sample project, in our full solution we are explicitly using the following:

  • RecordContainerGenerationMode="Recycle" 
  • CellContainerGenerationMode="Recycle"
  • RecordLoadMode="PreloadRecords"
  • AllowCellVirtualization="True"
  • AllowLabelVirtualization="False"