7

I have a launch dialog button which creates a view model of a window and bind it to the the window(it is having UI virutalization enabled). It takes only 1 second to launch the dialog at first click. But if I open the same dialog very frequently or back to back, it starts taking more time in populating the grid data source for next iteration. if I give some pause, then again open window, then it takes only approx 1 or 2 seconds.

for first time populating the item source it take only 1 second:
next time populating the item source it takes  2 second
next time populating the item source it takes  3 second
next time populating the item source it takes  6 second
next time populating the item source it takes  8 second

However, if I call GC.Collect() which is not recommended, then populating grid data source always takes approx 1 second. but calling of

Gc.Collect()
Gc.WaitForPendingFinalizer()
Gc.Collect()

cost me some time for every iteration.

I know calling GC.Collect is not a good option. Can anybody suggest how can I boost my application performance.

I am more concerned about the user machine as my machine is with very good configuration whereas user machine may not so fast.

Yogesh
  • 3,044
  • 8
  • 33
  • 60
  • 1
    Why does it take more time to open the dialog every time? Maybe you are loading too much data. Consider to [use paging](http://stackoverflow.com/questions/784726/how-can-i-paginate-a-wpf-datagrid)(in grid and in your sql query). – Tim Schmelter Feb 08 '16 at 08:54
  • Maybe you need to `.Dispose` of some resources before you close the dialog? – wildeyes Feb 08 '16 at 08:54
  • Tim, I also don't understand. probably I am missing something but don't know what.So looking for possible mistakes – Yogesh Feb 08 '16 at 08:56
  • What kind of dialog do you need to open "very frequently or back to back"?.. – Sayse Feb 08 '16 at 08:56
  • It is not the real use case but testing team is checking for load testing or performance testing. In real use case, user would open it once will do some operation, then will close. but in my case, they are just opening and closing the dialog back to back – Yogesh Feb 08 '16 at 08:58
  • Tim data is same it is loading only 200 rows object. I would have considered data virtualization if data were to be really large. but first time it take only 1 second to load same data and after 5-7 iteration it takes more time – Yogesh Feb 08 '16 at 09:00
  • Interesting question, i would love to know the cause too. Is it easy reproducible if I create a simple show dialog app? Also, do you check your memory consumption with each new dialog? just a wild guess could the slow down caused by disk-paging due to insufficient memory? – Peter Feb 08 '16 at 11:47
  • @Peter see my comment on answer, the reason which have been stated by CharithJ are the most possible cause. – Yogesh Feb 09 '16 at 03:05
  • @YogeshJoshi Thank you for letting me know. Great question and answer! – Peter Feb 09 '16 at 03:26

1 Answers1

3

It is difficult to pinpoint the exact issue without looking at the code. However, usually this can happen due to a few reasons.

  1. It loads more data (may be double?) evertime. You have indicated it loads only 200 records everytime. But make sure your logic is correct and it clears previous data before you re-publish.

  2. Make sure you unsubscribe from any event subscriptions. Sometimes there can be hiden events triggering for previous grid instances. You can easily check that by putting a break on an even handle and checking if it trigger more than once.

  3. Look at every Disposable instances you are creating and check if you dispose them appropriately. Probably you are not disposing disposable instance and that may be the reason that GC.Collect help.

  4. I am not quite sure about virtualization involvement here. Perform the same test without virtualization to make sure that's not the reason.

CharithJ
  • 46,289
  • 20
  • 116
  • 131
  • thanks CharithJ, I have figured out it was because of events which I was not unsubscribing but still I am wondering this event was not being raised automatically as I raise this event manually by performing certain action only. So it should not have been impacting performance. Now, I am more interested to know does storing so many event handler cause performance impact. I don't understand that thing. in terms of memory, they were not occupying that much memory. even though if they occupy more more, how does it impact the performance. could you give me some hint about it. – Yogesh Feb 09 '16 at 03:01
  • No need to occupy much memory to raise memory issues. May be you are dealing with Large objects? Have a read about https://www.simple-talk.com/dotnet/.net-framework/the-dangers-of-the-large-object-heap/ Remember to dispose all disposable objects just before they go out of scope. Implement IDisposable interface and unsubscribe from any events in the Dispose method. – CharithJ Feb 09 '16 at 03:04
  • thanks a lot for sharing this article, this is what exactly I was looking for – Yogesh Feb 09 '16 at 03:07