Sign in to follow this  

[.net] DataGridView in virtual mode lag

This topic is 3489 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I'm doing a simple hex editor program for learning purposes (I want it to be my first program with undo/redo support =)), however, I'm having some trouble with a DataGridView control in Virtual Mode. Here's a screenshot of my (currently basic) application with my custom HexadecimalDataView control, which is composed only of a DataGridView control : Thanks to ImageShack.us for hosting. Here's my problem : When I launch my program, nothing happens for about 10 seconds before my program shows up. During that time, one of my processors is used at 100%. However, my memory usage stays at 20k (which is perfectly normal). What's more, when selecting cells, the application lags a lot and a processor is used at 100% again. When not doing anything, the application behaves normally both in memory usage and processor usage. I handle the CellValueNeeded event by seeking and reading in the file, which amounts to quite a lot of seeking, but I don't think it justifies the lag I'm experimenting, especially the one at program launch. Any ideas on what's causing this? EDIT : Ok, I've set a breakpoint in m CellValueNeeded event handling method and it seems that it is called once for every cell (and there's one for every byte of the file) at the application launch. That's what's causing the launch-time lag. How can I disable this stupid behavior?

Share this post


Link to post
Share on other sites
Have you run it through a profiler? If not, you should download NProf and run your program through the profiler. That may give some insight.

Share this post


Link to post
Share on other sites
Thanks for the profiling idea, I still do not have profiling as a reflex.

Ok so I've run my program through the CLRProfiler. I've waited for about 5 minutes but the program still didn't show up (profiling makes it much worse). All this time it was using 100% of one cpu. I've stopped the profiling when the profiler's temporary log file reached 3.7 gigs =). The thing is, I don't really know how to read the outputted log info...

So I've downloaded nprof and run it (I changed the file my program was displaying for a file of 900k). After a few seconds the program popped and I closed it. Once again I wasn't too sure about how to interpret the data. Here's a link to the output if it can help.

Share this post


Link to post
Share on other sites
Ok, I've found out the first part of the problem. The initial lag was caused by the fact that some of my columns had AutoSizeToAllCells turned on, so the DataGridView had to check all cells to find the greatest width. Now that's fixed, startup time is < 1 second (still a tad slow but anyways).

However, I still have the selection lag problem. This may be cause by the fact that selection causes many redraws, and cell values are queried each time (unlikely as scrolling appears to be instant. Anyways, how can I fix this problem? Should I implement some kind of data caching system?

EDIT : I've disabled MultiSelect and it is now very responsive. Thanks for the help!

Share this post


Link to post
Share on other sites
yeah, the profiler definitely does make the program run slower, because it has to log every single function call. but it can be worth it in the end to suffer through it once or twice :)

For future reference, the number in the right column is the amount of time spent in that function and any functions it calls. So you notice that Main has 100% because the entire program was run from Main (as is usual).

From there, you need to look through the functions to find where all the time is being taken up. I usually only ever pay attention to the top box, and ignore the bottom box. If you click the plus box for a function, it shows all the functions that were called by that one, and how much of the total time was spent in each. In this case I notice DataGridView.WndProc has taken 45% of your program's time, which was most likely caused by the issues you said you fixed :) But if you openned that up, it might give some insight as to what the issue might have been, if you didn't already figure it out.

Share this post


Link to post
Share on other sites

This topic is 3489 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this