Lazy Evaluation

Paying a performance penalty for a computation you ultimately may not need is a bad idea. It happens way too often in complex code. You should not perform costly computations “just in case.” Costly computations should be performed only if necessary. That often means deferring computations until they are actually needed, hence the name Lazy Evaluation [Mey96, ES90].

Back in the days of pure C programming we were in the habit of defining all of our variables up front, at the beginning of each routine. In C++, object definitions trigger constructors and destructors and that may be expensive. It leads to eager evaluation—something we want to avoid. The Lazy Evaluation principle suggests that we ought to delay object definition to ...

Get Efficient C++ Performance Programming Techniques 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.