I have a method in c# code behind..which needs to be executed 10000+ lines from Assemblies as well as in Child group Methods. My Question is How to optimize it? It is taking more than 40 Seconds Load to 500 Rows in my page my own gridview which is designed by myself.
-
41. Find the part that's slow, and 2. Make it faster. Seriously, general optimization techniques aren't worth discussing until you know what part of your code is eating the time. – 3Dave Nov 10 '09 at 06:15
-
2Yeap, that's called profiling. Nice thing. – sharptooth Nov 10 '09 at 06:17
-
I commend (and upvote) you for determining that certain problem routine is taking too much time, and having a good idea how long it takes, before asking optimization questions here. Too many people ask optimization questions without such knowledge. – David Thornley Nov 10 '09 at 15:20
2 Answers
Profile your code. That will help you identify where its slow. From reading your post , optimizing might take you a long time since you have alot of code and data.
Virtualize as much as you can. Instead of loading 500 rows, can you try loading 50 rows first, show your UI then load the remainder 450 rows asynchronously ? This doesnt speed up your application, but at least it seems working much quicker than waiting 40 seconds.

- 7,515
- 1
- 25
- 41
-
Also, test things that you think are improvements. They may not be. – David Thornley Nov 10 '09 at 15:17
This method is very simple, but it can pinpoint the activities that would profit the most by optimizing.
If there is a way to speed up your program, it is taking some fraction of time, like 60%. If you randomly interrupt it, under a debugger, you have a 60% chance of catching it in the act. If you examine the stack, and maybe some of the state variables, it will tell you with great precision just what the problem is. If you do it 10 times, you will see the problem on about 6 samples.

- 1
- 1

- 40,059
- 14
- 91
- 135