Design Pattern Efficiency

Does anyone know any sites / books / articles on best practices or theories around design patterns in high-performance applications? It seems that many patterns use indirect / abstraction / encapsulation in such a way that this can affect performance in computationally intensive code. Head First Design Patterns and even GoF mention the possibility of performance hits with many patterns, but without more specific tips on how to deal with this.

+6
c ++ performance design design-patterns
source share
9 answers

I am surprised that we are not asking what performance problems you have!

In my experience, performance problems are usually related to specific conditions and situations. Design patterns, on the other hand, are solutions to more general and abstract problems. It would seem a little inconvenient to approach both in the same text: and what, perhaps, in many “unstructured” solutions, if the author compares the performance of the design pattern? When the performance problem is common, there are probably already templates to solve them: weight is a good example.

The fines imposed using the design pattern have a finite, very small set: introducing virtual calls, adding delay due to delegation, additional memory consumption due to the distribution of objects, etc. If after profiling you notice that this is the cause of your problems, there are known ways to minimize them.

Knowing patterns can be useful for solving performance issues. First, someone already mentioned that patterns break the problem down into smaller bits: this can make it easier to identify the source of the problem and highlight the ugly but perfect code. They also provide a framework for the reasoning and expectations of developers. If you must introduce a deviation for performance reasons, it will be obvious: "Except here, when we give up X and do Y to improve performance, this is a chain of responsibility." These are the rules that need to be broken if necessary.

(Alas, there is one very good template for getting good performance: measurement, accurate, correction.)

+5
source share

There are design patterns to help you understand how to create software or improve its flexibility. How you implement the template determines what quality of execution (or benefit) you will see from its use.

Some patterns exist because the general way of structuring generally leads to faster programs. But unlike algorithms, there is no good way to really formally analyze a template to determine how slow or fast it is.

My advice would be to use a template if it helps you figure out how to create a specific piece of code, or if you need to reorganize to make the code more flexible or understandable. If you are having performance issues, use standard profiling methods to find them.

If you are refactoring when confronted with performance issues, perhaps the cost is not worth the refactoring, or perhaps there is a way to mitigate it. If you are developing new code, perhaps there is a way to make a difference to fix the performance problem if it really lies in the necessary indirectness for the template to work.

+4
source share

The most specific tip: profile it in your application and see what impact it really has.

Any other advice will be much more general and may not necessarily apply well to how you implemented this template in your application with your compiler on your platform.

+3
source share

Design patterns are basically ways to break up your program into smaller parts that are easier to repeat, compose, construct, and test. Some design patterns will lead to code that is worse than a simpler design, but they have a significant advantage if you consider the 80/20 rule.

The 80/20 rule says that 80 percent of your program’s execution time will be spent executing 20 percent of this code. When your program is pleasant and modular, it is easy to drop it into the profiler and see which component can be tuned / optimized, or where it makes sense to go with a less flexible design to increase productivity. Having a design that's far apart initially makes it easier to find hot spots.

+1
source share

One term that can help you get the best hits is "template language." This is a set of templates that are combined for some purpose. If you have a more specific goal - high performance, someone may have a path through the templates for your domain, for example: a template language for parallel software . Here's another good collection of concurrent programming patterns from UIUC; a bunch of patterns work.

The guys from ACE / TAO have a lot of documents on high-performance network templates using C ++

+1
source share

The design pattern really focuses on how you structure the code and define the abstraction and interaction of the class. The performance of your computing performance will mainly be accomplished by the way you write the actual implementation of the code (method body).

For C ++, I definitely suggest reading Scott Meyers' book, Effective C ++ and More Effective Series of Books in C ++, which in itself shows a lot of idioms when writing high-performance code.

0
source share

You can read the Herb Sutter entries in the Effective Concurrency section for things related to multithreaded and concurrency samples and how they affect performance.

http://herbsutter.com/

0
source share

GoF design patterns are the use of proven patterns to solve common problems with elegant, maintainable code. They are not performance oriented.

If you need templates for performance, you may need to consider system architecture templates, algorithms, data structures, etc.

What does your application do?

If your application is in C ++ and written reasonably, the likelihood that your code will run quickly on modern hardware until it has to wait for I / O. An exception would be something like real-time image analysis, which would be very intense.

If performance is a problem, do you really mean I / O performance? (disk, DB, network, etc.)

There are “patterns” that allow your application to work even with frequent waiting for I / O (asynchronous callbacks, etc.).

If you are dealing with an uneven load, in which the peak load can be much higher than the average load, the commonly used architecture pattern is to disable system components with message queues.

0
source share

Remember the old adage: “You can have it good, fast and cheap, choose two”
Design patterns appeal to the good. A good foundation is needed, so the code can be accurate and convenient. If performance is a problem, then check and then optimize partitions that give you problems. Many times, performance is simply a matter of choosing the right algorithm. But this may mean that you need to break into some terribly optimized code for 10%, which takes 90% of the time. Just make sure you comment on S ^^ T.

0
source share

All Articles