{"id":32,"date":"2003-06-18T20:35:31","date_gmt":"2003-06-18T19:35:31","guid":{"rendered":"http:\/\/www.nobugs.org\/blog\/archives\/2003\/06\/18\/update-debt\/"},"modified":"2003-06-18T20:35:31","modified_gmt":"2003-06-18T19:35:31","slug":"update-debt","status":"publish","type":"post","link":"https:\/\/www.nobugs.org\/blog\/archives\/2003\/06\/18\/update-debt\/","title":{"rendered":"Update Debt"},"content":{"rendered":"<p>A random &#8220;design pattern&#8221; which just popped into my head:<\/p>\n<p>Imagine you have some large data structure which is expensive to update.  Maybe it&#8217;s a list of integers and you want to clamp each element to be between 0 and 100.   Normally, you&#8217;d go through each element, perform the check and update it if required.<\/p>\n<p>Instead, I suggest keeping the original list and creating a seperate log of the &#8216;modifications&#8217; which have been made to it.  So now you have the original list and a note saying &#8220;by the way, when you read an element you also have to clamp it to the range 0-100&#8221;.  Now you&#8217;ve made the update cheap, but accessing the data is more costly.<\/p>\n<p>However, if your program is otherwise idle later on, it can come back and coalesce everything back down.<\/p>\n<p>So you&#8217;re basically saving time in your &#8220;change it&#8221; code, paying it back a little at a time in the &#8220;access it&#8221; code, and you&#8217;ve got the option to pay off the debt entirely when you&#8217;ve got a bit of idle time spare.<\/p>\n<p>Whether this is useful or not depends on the frequency and cost of updates and accesses.  I&#8217;m noting it here as another potential &#8220;tool in the box&#8221; for algorithmic optimization.  It probably lives next to memoization and similar such techniques.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A random &#8220;design pattern&#8221; which just popped into my head: Imagine you have some large data structure which is expensive to update. Maybe it&#8217;s a list of integers and you want to clamp each element to be between 0 and 100. Normally, you&#8217;d go through each element, perform the check and update it if required. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-32","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/comments?post=32"}],"version-history":[{"count":0,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/32\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/media?parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/categories?post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/tags?post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}