{"id":36943,"date":"2004-12-20T07:00:00","date_gmt":"2004-12-20T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/12\/20\/dont-save-anything-you-can-recalculate\/"},"modified":"2004-12-20T07:00:00","modified_gmt":"2004-12-20T07:00:00","slug":"dont-save-anything-you-can-recalculate","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20041220-00\/?p=36943","title":{"rendered":"Don&#8217;t save anything you can recalculate"},"content":{"rendered":"<p>Nowadays, a major barrier to performance for many classes of programs is paging. We saw earlier this year that <a href=\"http:\/\/weblogs.asp.net\/oldnewthing\/archive\/2004\/03\/17\/91178.aspx\"> paging can kill a server<\/a>. Today, another example of how performance became tied to paging.<\/p>\n<p> The principle is &#8220;Don&#8217;t save anything you can recalculate.&#8221; This of course, <a href=\"http:\/\/weblogs.asp.net\/oldnewthing\/archive\/2004\/12\/16\/317157.aspx\"> seems counterintuitive<\/a>: Shouldn&#8217;t you save the answer so you don&#8217;t have to recalculate it? <\/p>\n<p> The answer is, &#8220;It depends.&#8221; <\/p>\n<p> If recalculating the answer isn&#8217;t very expensive and has good data locality, then you may be better off recalculating it than saving it, especially if saving it <strong>reduces<\/strong> locality. For example, if the result is stored in a separate object, you now have to touch a second object&mdash;risking a page fault&mdash;to get the saved answer. <\/p>\n<p> Last time, <a href=\"http:\/\/weblogs.asp.net\/oldnewthing\/archive\/2004\/12\/17\/323556.aspx\"> we saw how Windows&nbsp;95 applied this principle<\/a> so that rebasing a DLL didn&#8217;t thrash your machine. I&#8217;m told that the <a href=\"http:\/\/office.microsoft.com\/en-us\/FX010857911033.aspx\"> Access<\/a> team used this principle to reap significant performance gains. Instead of caching results, they just threw them away and recalculated them the next time they were needed. <\/p>\n<p> Whether this technique works for you is hard to predict. If your program is processor-bound, then caching computations is probably a good idea. But if your program is memory-bound, then you may be better off getting rid of the cache, since the cache is just creating more memory pressure. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nowadays, a major barrier to performance for many classes of programs is paging. We saw earlier this year that paging can kill a server. Today, another example of how performance became tied to paging. The principle is &#8220;Don&#8217;t save anything you can recalculate.&#8221; This of course, seems counterintuitive: Shouldn&#8217;t you save the answer so you [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-36943","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>Nowadays, a major barrier to performance for many classes of programs is paging. We saw earlier this year that paging can kill a server. Today, another example of how performance became tied to paging. The principle is &#8220;Don&#8217;t save anything you can recalculate.&#8221; This of course, seems counterintuitive: Shouldn&#8217;t you save the answer so you [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/36943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=36943"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/36943\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=36943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=36943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=36943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}