Tuesday, March 1, 2011

What constitutes a good memory profile?

In designing any desktop applications, are there any general rules on how much memory should the application uses?

For heavy-weight applications, those can be easily understood or at least profiled such as Firefox or Google Chrome. But for smaller utilities or line-of-business application, how much is an acceptable amount of memory usage?

I asked because I've recently come across a trade-off between memory usage and performance and wonder if there is any general consensus regarding it?

EDIT: Platform is Windows XP for users with machine just capable of running rich internet applications.

My specific trade-off problem is about caching a lot of images in memory. If possible, I'd love to have my app cache as much as the user's memory will allow. I have done it so that the application will cache upto a certain maximum limit considering memory pressure at the moment..

But what would be a good number? How do you come up with one? That's the point I'm asking.

From stackoverflow
  • This depends on your target PC hardware. If your application uses too much memory then it will be slow while windows pages. TEST! Try both options in your compromise, and some in between if it makes sense. Run the tests on a typical machine that your users would use and with a sensible number of other applications open. So for most people that is Outlook and probably an instance or 2 of Internet Explorer (or the mail client/browser of your choice). I work in an organistion where uses of my application are also likely to be running some other custom applications so we test with those running as well. We have found that our application used too much memory, and makes switching application painfully slow so we have slowed our application slightly to reduce its memory usage. If you are interested our target hardware was originally 512Mb machines becuase that was what our common standard spec workstation was. Several PC's had to be upgraded to 1Gb though becuase of this application. We have now trimmed its RAM usage a bit but it is written in VB .NET and most of the memory used seems to be the framework. PerfMon says the process is using aroung 200Mb (peak) but that the managed heap is only around 2Mb!

  • This depends entirely on your target platform, which is more or less a business decision. The more memory you will need, the less customers will be able to use your software. Some questions to ask: How much memory do your customers (or potential customers) have installed in their computers? What other applications will they run simultaneously with your application? Is your application something assumed to be running exclusively (like a full screen computer game), or a utility which is supposed to run mostly in background, or to be switched into it from other applications often?

    Hear is one example of a survey showing a distribution of installed RAM in systems of people playing games via Steam (source: Valve - Survey Summary Data):

    • Less than 96 Mb 0.01 %
    • 96 Mb to 127 Mb 0.01 %
    • 128 Mb to 255 Mb 0.21 %
    • 256 Mb to 511 Mb 5.33 %
    • 512 Mb to 999 Mb 19.81 %
    • 1 Gb to 1.49 Gb 30.16 %
    • 1.5 Gb to 1.99 Gb 6.10 %
    • 2.0 Gb 38.37 %

    A conclusion I would draw from a survey like this in my domain (computer games) is I can reasonably expect almost all our users having 512 MB or more, and vast majority having 1 GB or more. For a computer game which is supposed to run exclusive this means working set around 400 MB is rather safe and will limit almost no one out, and if it provides a significant added value for the product, it may have a sense to have a working set around 800 MB.

    chakrit : It's a utility that will run mostly in background.
  • There is no absolute answer for this. It depends on too many variables.

    Here are some trade-offs for consideration:

    • What device/platform are you developing for?
    • Do you expect your user to use this software as the main purpose for their computer (example maybe you are developing some kind of server software)
    • Who is your target audience, home users? power users?
    • Are you making realistic expectations for the amount of RAM a user will have?
    • Are you taking into consideration that the user will be using a lot of other software on that computer as well?

    Sometimes it's possible to have your cake and eat it too. For example if you were reading a file and writing it back out, you could read it chunk by chunk instead of reading the whole file into memory and then writing it out. In this case you have better memory usage, and no speed decrease.

    I would generally recommend to use more RAM to get better speed if you must. But only if the RAM requirements are realistic for your target audience. For example if you expect a home user that has 1GB of RAM to use your program, then don't use 600MB of RAM yourself.

    Consider using more RAM in this instance to get better speed, and to optimize some other part of your code to use less RAM.

    Edit:

    About your specific situation of caching images. I think it would be best for you to allow the user to set the amount of caching they would like to perform as an option. That way people with a lot of RAM can put it higher for better performance, and the people with little RAM can set it low.

0 comments:

Post a Comment