Chapter 91. WET Dilutes Performance Bottlenecks

Kirk Pepperdine

image with no caption

THE IMPORTANCE OF THE DRY PRINCIPLE (Don’t Repeat Yourself) is that it codifies the idea that every piece of knowledge in a system should have a singular representation. In other words, knowledge should be contained in a single implementation. The antithesis of DRY is WET (Write Every Time). Our code is WET when knowledge is codified in several different implementations. The performance implications of DRY versus WET become very clear when you consider their numerous effects on a performance profile.

Let’s start by considering a feature of our system, say X, that is a CPU bottleneck. Let’s say feature X consumes 30% of the CPU. Now let’s say that feature X has 10 different implementations. On average, each implementation will consume 3% of the CPU. As this level of CPU utilization isn’t worth worrying about if we are looking for a quick win, it is likely that we’d miss that this feature is our bottleneck. However, let’s say that we somehow recognized feature X as a bottleneck. We are now left with the problem of finding and fixing every single implementation. With WET, we have 10 different implementations that we need to find and fix. With DRY, we would clearly see the 30% CPU utilization and would have a tenth of the code to fix. And did I mention that we don’t have to spend time hunting down each implementation? ...

Get 97 Things Every Programmer Should Know now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.