5

Always the first thing i hear when we talk about design pattern is like a documented solution to common architectural issues.

I am curious to know which design patterns are good solutions to improve performance of an application in general.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Siva
  • 1,265
  • 4
  • 17
  • 24
  • 1
    @user619133, the pattern that you apply is specific to the problem that you are trying to solve. It is a misconception, that 1 design pattern can fit into all solutions. – Devendra D. Chavan Feb 16 '11 at 06:37
  • 1
    What is the answer to life in general? – user541686 Feb 16 '11 at 06:39
  • 6
    [Which color has the most RAM?](http://dilbert.com/dyn/str_strip/000000000/00000000/0000000/000000/20000/1000/100/21168/21168.strip.gif) – Cody Gray - on strike Feb 16 '11 at 06:41
  • Somewhat funny that this question is linked from the official Overflow Blog with "design patterns being discussed". I thought that Stack Overflow is intended as a Q&A site to serve as knowledge base, not a discussion forum. Not sure if this question stands the test of time and would still qualify as an "on-topic" question today. – knittl Oct 13 '22 at 13:20

5 Answers5

11

On a more serious note, design patterns will probably reduce performance. From my experience, the usage of design patterns gives cleaner, more maintainable code. Should you need to optimize anything, you would probably need to de-design pattern the code.

Often performance of code is dependent on a relatively small piece (a data structure, a function, or even a single loop), so it doesn't go into the scope of design patterns any way. Changing a straight forward function in C to a super optimized version in assembly probably won't change the way the entire class behaves.

Eli Iser
  • 2,788
  • 1
  • 19
  • 29
  • In one way you are right, the most importance use of a design pattern i believe is in making the code easily extensible , maintainable and mananging the memory in an efficent way – Siva Feb 17 '11 at 05:23
11

Flyweight reduces memory consumption.

The Proxy pattern can be used for speed optimization.

The Bridge pattern can change the implementation of an abstraction on the fly - always picking the most efficient one.

Karl
  • 3,170
  • 1
  • 21
  • 28
  • These patterns are really useful.In small devices where memory is still a problem, managing the memory increases the performance. I believe singleton pattern also improves the memory management effectively – Siva Feb 17 '11 at 05:20
  • 2
    Singleton solves the problem of maintaining only one instance at time. It doesn't solve any efficency problem. Besides, it is the most tricky pattern which should be avoided unless there's no other solution (in fact there always is). – dzendras Feb 17 '11 at 22:45
  • Yes you are right.After seeing you comment i did some googling and got these links http://stackoverflow.com/questions/1392315/problems-with-singleton-pattern , http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/, http://misko.hevery.com/2008/08/25/root-cause-of-singletons/. In a nutshell singleton pattern are really bad for memory, since it never gets freed up. And it can lead to unclear code,bad for testing.The only good place as pointed out where it can be used is logging – Siva Feb 19 '11 at 04:51
  • For flyweight pattern this link provides good explanation of why it is good for performance http://www.javaworld.com/javaworld/jw-07-2003/jw-0725-designpatterns.html?page=5 "allocating a huge number of (typically small) objects can be detrimental to your Java application's performance, although modern JVMs have greatly reduced the penalty you must pay for such excess. If you find that your application is instantiating numerous objects of a particular type, you might consider using the Flyweight pattern to share a limited number of those objects" – Siva Feb 20 '11 at 03:40
2

Object Pool Pattern

The object pool pattern is a software creational design pattern that uses a set of initialized objects kept ready to use – a "pool" – rather than allocating and destroying them on demand.

Object pools are primarily used for performance: in some circumstances, object pools significantly improve performance.

Timeless
  • 7,338
  • 9
  • 60
  • 94
1

There is nothing like that.Design patterns are used to make your development and maintance easier.

mostly design patterns are used for

design pattern is a general reusable solution to a commonly occurring problem in software design
anishMarokey
  • 11,279
  • 2
  • 34
  • 47
1

Probably the "don't-do-stupid-tings" pattern. If followed to the tee, you'll find it beats:

  • Factory
  • Singleton
  • MVC
  • Aspect Oriented Programming
  • Extreme Programming and Extreme Programmers (mercilessly)
  • DotNetNuke (twice)
  • Drupal (once)

Hands down

jpstrikesback
  • 2,300
  • 14
  • 18