views:

238

answers:

4

I have a C#/.Net application which seems to use most of it's CPU time doing updates to a DataGridView. I manually update the data about every 1.5 seconds, updating only the data that has changed. This ends up being about 250 updates every 1.5 seconds. I'd like to reduce that 1.5 seconds to a much smaller number (0.5 seconds maybe). I've profiled and optimized as much as I can, and while the performance is ok, I'd like it to be faster.

My question is, will upgrading the video card from an Nvidia FX1800 to an Nvidia FX3800 produce a significant speedup?

+1  A: 

GDI+ operation doesn't depend much of graphic CPU since it uses only basic accelerated operation that every graphic card supports (lines, rectangles, etc.).

I would guess that problem here is that you are not "hiding" control during updates. Check BeginUpdate/EndUpdate methods if they are available. If not, setting visible to false, updating and setting visible to true can sometime solve problem.

Josip Medved
+1  A: 

Your time is almost certainly not being spent in drawing the screen, but in updating the internal representation of the data, so no that won't help.

EDIT:

To find out where the time IS being spent, look into a profiler. I personally prefer the one from Red Gate

Eric J.
+1  A: 

My gut says "No."

CPU time is not GPU time. If your CPU is busy updating the view, you might need to change the system to a more CPU friendly view. It sounds like it is not lazy loaded and is getting all of the data and all of the updates. How big is your range of values? If you do not have many values, this could be fine. My suspicion is that you have a large number of values and it is maintaining the entire list in memory. This is bad for a few reasons. It takes a lot of memory, you need to pay attention to all of the changes (not just the ones that affect your current display), it is a lot of content to shift around and update.

I would look for a more friendly control that only loads part of the data.

The graphics card that you have should be able to render the view in a very small fraction of a second. Try grabbing the application and wildly moving it around the screen. This will give you an indication of how quickly it can be updated (yes, not entirely accurate since it is probably being cached).

How big is your list?

Jacob

TheJacobTaylor
I am only calling the PropertyChanged event for cells which have actually changed. Is think/assume that this is what you mean by "lazy loading".The DataGridView has only about 30 rows with about 30 columns, so there is not a huge amount of data displayed. The problem seems to be related to the number of updates per second.
Joe H
Ok. That changes a bit. I would take a crack at swapping the whole thing out on updates. 900 cells of which 150 change is a pretty high update. Unless you can stop updates, update all changes, then start updates (which would probably be faster). 900 Cells should be instant. I would just record the scroll position, refresh the UI, then restore the scroll position. Hopefully this will be seamless. If this does not work, you need to look for another control. This is a small amount of data. Lazy loading was thinking about 10's of thousands of records and only putting 100 or so in the control.
TheJacobTaylor
I'm sorry, I'm not sure what you -- TheJacobTaylor -- mean by the above comment. What does "swapping the whole thing out on updates" mean? Currently I have a Timer whose Tick event handler raises PropertyChanged events for any cells which have changed. This timer has an interval of 1.5 seconds.Also, when you say "refresh the UI", do you mean call DataGridView.Refresh()?
Joe H
I was thinking that you had tons of records where only a small portion changed. It turns out that you have 900 records and almost 30% of them change each update. It would likely be faster to completely replace the entire data set rather than incrementally update the cells. Basically, with 30% changing at a time it is probably more efficient for the system to rebuild the entire view from scratch than to update several hundred little sections. Julien is updating the full data set for 1000 items every few ms. Profile the code or try replacing the entire dataset to see what happens.
TheJacobTaylor
A: 

I used a DataGridView presenting a list of 1000 items in an application where the data (and by that, I mean the whole list) is refreshed every 50ms with almost no performance penalties. So I don't believe that what you want to do is too much for the DataGridView.
As Eric J. suggests, you should profile your code, I'm sure you'll find that your performance problem comes from somewhere else in the code.

Julien Poulin
Are you using virtual mode?
Joe H