Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF: what's the most efficient/fast way of adding items to a ListView?
    primarykey
    data
    text
    <p>I need to display lots of rows in a grid added at a pretty high frequency (up to 10 rows per second in some cases) I chose ListView because I assume is the fastest grid control in WPF. (certainly a lot faster than GridView)</p> <p>CPU utilization gets pretty high after couple hundred thousand items were added and they continue to come in. This is rather surprising, as ListView renders only the visible rows, so it should not matter how many are added in total. </p> <p>My first approach was binding it to ObservableCollection but after a while, the CPU utilization goes up, and the whole Window get jittery. </p> <p>Than i tried binding it to a regular List, which appears to be faster, however i do need to call the .Refresh() on the list often, which after a while slams the CPU as well. </p> <p>Than i attempted <a href="https://stackoverflow.com/questions/3300845/observablecollection-calling-oncollectionchanged-with-multiple-new-items">subclassing ObservableCollection</a> to chunk inserts hoping that batching them would improve performance/decrease cpu workload, but this approach appears to require calling CollectionView.Refresh which is the same as calling Reset() on the collection, and also ineficient when there are lots of items in the collection. </p> <p>Clearing the observablecollection and than calling myListView.Items.Refresh() to bring it back down to 0 brings cpu usage back to the starting point. </p> <p>Starting to run out of ideas here.. Again, my aim here, is to add/display lots of items and display 8 column grid, in the most performant manner.. ListView seems good, there just have to be some ways i could further tweak it..</p> <p><strong>UPDATE</strong></p> <p>after profiling, ObservableCollection 800k rows in the grid, the most cpu intensive work is done by :</p> <ul> <li>(75%) System.Windows.Media.MediaContext.RenderMessageHandler(object resizedCompositionTarget)</li> <li>(20%) ObservableCollection.OnCollectionChanged(NotifyCoolectionChanged..)</li> </ul> <p>although depending on session those numbers vary greatly..</p> <p><strong>UPDATE 2 .. ok BindingList appears to be the clear winner here.</strong></p> <p>here are results (in ticks) side by side with 1 million rows each (and adding 10 items per second):</p> <p>ObservableCollection: <a href="https://i.imgur.com/7ZoSv.png" rel="nofollow noreferrer">http://i.imgur.com/7ZoSv.png</a></p> <p>BindingList <a href="https://i.imgur.com/jm5qF.png" rel="nofollow noreferrer">http://i.imgur.com/jm5qF.png</a></p> <p>you can see overall drop in CPU activity, and about half the ticks required to process the tree in Binding List case! My thanks to Akash for this great idea. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload