Ever decreasing cost of main memory

I have blogged about the relative cost of memory to the cost of your time. Memory in servers is so cheap that for small amounts of memory, it just isn't worth your time to introduce complexity into your application to try to save it.

The average salary for a developer in the UK is £40,000 and the average cost of memory is £5 per GB. The cost to your organisation for both is higher and if you have many machines saving a 1 MB on 1000 machines saves 1 GB, however memory is so divisible you can quickly run into small amounts of memory which are not worth your time saving.

Hard disk space is even cheaper and most people get its not worth keeping your disks completely clean all the time, because the cost of deleting a file you later need is high, but also the value of the space you save is not worth your time. A typical 2 TB of mirrored disk in a network appliance costs about £300.

Your timeMain memory to save in total    Disk space to save
Blink of an eye (20 ms)20 KB1.7 MB
One second1 MB33 MB
One line of tested code (2 mins)120 MB3.5 GB
A small sized well tested
library, 100 lines (0.5 days)
14 GB500 GB
A medium sized well tested,
documented library, 1000 lines (1 week)
140 GB5 TB

For self learning, interest or fun you might think about ways of saving small amounts of memory or disk. But for work, the most efficient way to program may be to save your time and those who have to maintain your code, and waste some hardware resources in the process. BTW: hardware resources are more re-usable than your time.


  1. In my opinion, the intereset low cost of memory is that we can put most data stores and caches in memory. No need to promote bloat. While memory itself is cheap, memory management (GC...) can hurt performance...

  2. @mauhiz, I tend to advocate pre-allocation and recycling of objects. I am not a fan of creating a discarding lots of objects. But even this is a trade off between the cost of optimising the code and the cost of not optimising the code. I think developers should have a view on when it is worth worrying about and when its better to worry about other things (like maintainability)

  3. I totally agree with your blog post and even more with your last answer.

    However, after worrying about the business logic and besides performance, we, the developers, have to take care with the resources. They are cheap, but not infinite nor eternal.

    It's easier and cheaper to buy more hardware, but it won't be able to contain unnecessary huge data.

    I mean, that's true, don't waste your time neither your company's money in optimizations that don't worth it, but don't select an entire database in objects and then put them in an HttpSession per user just in case.

  4. Sir,

    Best short discussion I've ever seen on this topic. Thank you. As a Java instructor for the last 12 years, I've taught for the entire time that it is universally true (+/- 3%) that maintenance programming cost is vastly more important than efficiency...and that is the core thought behind the language of Java.

    Thank you again for the post.

  5. Very true, for code that runs on servers you control. I'd pass it up the chain of command, if my time weren't much better spent sending out resumes.

    But lots of code still runs on customer's machines, and that changes the tradeoffs completely.

  6. @HA HA HA, The customer trade offs are different esp when the client doesn't see things the way you do.

    The way I see it, if you are saving 1 MB on 1000 client machines that still about 1 GB at least.


Post a Comment

Popular posts from this blog

Java is Very Fast, If You Don’t Create Many Objects

System wide unique nanosecond timestamps

Comparing Approaches to Durability in Low Latency Messaging Queues