What are some resources I can use to learn profiling/optimizing?

后端 未结 11 1944
醉梦人生
醉梦人生 2020-12-24 10:03

I just inherited a C# project that runs way to slow and will have to start optimizing it. What I wanted to do first is learn a little more about profiling/optimizing since I

11条回答
  •  情深已故
    2020-12-24 10:28

    I've used profilers before, they can be helpful, but you can get a lot of help just from creating a singleton stopwatch type class and "Click" it (have it print out the time since the last click and what was just done that took that time) before and after methods you think might be problematic.

    If speed is a problem throughout the app, you're probably not going to be able to do too much about it, but you might be able to make a few changes...

    Look for inner loops. These are performance death. An inner loop can be caused by something as simple as indexing into a linked list, or doing an insertion sort into an array-based list. (Once I had a list box that was taking 10-20 minutes to fill with tens of thousands of entries, although that's too many entries, the worst part was that it was sorting it by inserting each entry into an array list).

    Look for cases where you are doing long operations based on keypresses. These should almost always be done outside the main thread.

    Don't even THINK of optimizing things like numbers of classes or how often they are instantiated, string concatenation (outside of loops), nulling out variables or any of the other silly strategies that seem like they should help. I've tried a few and always ended up feeling silly when I actually slowed things down because I wasn't as smart as the runtime is at most things.

提交回复
热议问题