Caching

2021-03-09 11:48PM


I was cracking a joke about how we should buy the Chris/Harrison/Luke household a silverware organizer for their drawer when Chris remarked that they preferred to optimize for insertion time, which is constant (just dump all of the utensils into the drawer, independent of how many there are) vs. the roughly linear behavior of sorting utensils into compartments one-by-one. For a small number of utensils, lookup is constant time in both cases, since the common utensils are easily distinguishable even in a jumble.

There are a number of directions we could take this--e.g. scalability, aesthetics--even if the original answer was a joke, which it probably was. Standards for cleaning and organizing can be super divisive, so it was an interesting reminder of the trade-offs people make that also suggests additional connections to computer science.

Caching is one of the most ubiquitous concepts in CS, based on the fairly straightforward concept of locality: things that are close to each other, for some definition of close, are likely to be used together. In computing, this could mean sequential pieces of data in memory, or a query that was just performed several times in a row. In life, I suppose this is why we keep the utensils in a single drawer, or the cleaning supplies in one cabinet. In terms of cleaning, leaving stuff out is a form of caching--you just used it and will probably use it again, so at this level it makes sense to keep it there instead of putting it away. Of course, there are other considerations; like clutter, the extreme being all of your belongings strewn on the ground, which affects the lookup efficiency; or aesthetics, an example being a made vs. unmade bed.

My violin and guitar stands are two of my most useful caches. You might think that it doesn't take much time or effort to remove the instruments from their cases, but I've found that even the smallest obstacle will drastically reduce the chances of overcoming my laziness. The stands also have some aesthetic value, and are a good physical, visual reminder to practice.

It's kind of interesting that we can influence our habits this way, by intentionally making tasks easier or more difficult to execute. Other examples for me could be leaving a book on my nightstand, or I guess not having a couch to watch TV from. Tangentially, I recall an old language design blog post describing the concept of "syntactic salt" (as opposed to syntactic sugar), where you can encourage better program characteristics through syntactic choices.


Back
Permalink
Next