Lazy Evaluation vs Eager Evaluation

When dealing with huge data, performing complex operations takes a lot of time due to the increased requirement of computing power.:speech_balloon:

When a compiler encounters an expression, it usually tries to evaluate it. While most languages do this immediately, it’s not very efficient always. Not all expressions are worth evaluating as they might not be needed at that moment of time in execution.:thinking:

By Lazy Evaluation, the evaluation of expressions is delayed till they are actually needed. This makes it much more efficient and saves memory and compute resources, allowing you the liberty to work on any size of data.:bulb:

The operations are stored as graphs of multiple steps. This means that whenever the operation/action is explicitly called, it will evaluate as per the graph. The results are stored in the form of dictionaries/memos which are looked up whenever a variable is needed.:repeat_one:

Lazy evaluation is used by many libraries/frameworks like Vaex and Spark to easily manage big data.:zap::zap:

Eager evaluation computes all the possible variables as soon as it encounters them, making it easier to understand and debug the code.

However, it depends on the application as to which technique should be used for best results.