Another Enlightment

The reality we can put into words is never reality itself.

In quantum mechanics, the Uncertainty Principle states that we cannot simultaneously know both the position and momentum of a particle with perfect accuracy.

Mathematically, it is expressed as ΔxΔp/2\Delta x \cdot \Delta p \geq \hbar/2 where Δx\Delta x is the uncertainty in position, Δp\Delta p is the uncertainty in momentum, and \hbar is just a relatively small constant (the reduced Planck constant).

This principle finds a surprising analog in software development. When measuring the performance of a system, you can never measure the precise position of an operation and its performance at the same time.

This is because measuring time, i.e. performance.now(), is a side effect of the operation itself. The act of measuring time changes the performance of the operation. The more accurate the measurement, the more it affects the operation. If you put the measurement on the very top level, you will measure the performance of the whole system, not the operation itself.

For example in a large application, I can measure the precise time of a large function block like this, without knowing the actual position (or distribution) of the time spent inside it:

function main() {
  const start = performance.now()
  startWork()
  const end = performance.now()
}

Or I can measure the cost of a precise, low-level operation that can be used multiple times:

function readFile() {
  const start = performance.now()
  // implementation...
  const end = performance.now()
}

But the side effect of performance.now() is that it changes the behavior of the operation itself. And that scales exponentially with the size of the system.

This is also called the Probe Effect. The act of measuring changes the thing being measured. Or Heisenbugs.

We can never know anything. — Werner Heisenberg