# Lazy Evaluation

> An approach in which a value is computed only when something consumes it.

Record: `architecture:lazy-evaluation`
Kind: approach
Layer: [Execution Core](https://banes-lab.com/records/layer/execution-core.md)
Severity: contextual
Scope: computation, collection, stream
Canonical: https://banes-lab.com/ontology#architecture-lazy-evaluation

Listed in [Architecture principles](https://banes-lab.com/api/records/architecture.md), after [Pipeline Architecture](https://banes-lab.com/records/architecture/pipeline-architecture.md) and before [Sequential Access](https://banes-lab.com/records/architecture/sequential-access.md).

## Repair

- Refactored by: Use Iterator/Generator, Defer Computation
- Detected by: eager loading of large unused data
- Violated by: computing/materializing unused results
- Measured by: avoided work, memory reduction
- Enforced by: performance tests

## Requires

- [Deferred Execution Semantics](https://banes-lab.com/records/lexicon/deferred-execution-semantics.md)

## Reinforces

- [Memory Efficiency](https://banes-lab.com/records/architecture/memory-efficiency.md)

## Enables

- [Avoiding Unneeded Work](https://banes-lab.com/records/lexicon/avoiding-unneeded-work.md)

## In tension with

- [Debuggability/Resource Lifetime](https://banes-lab.com/records/lexicon/debuggability-resource-lifetime.md)
- [Eager Full Materialization](https://banes-lab.com/records/lexicon/eager-full-materialization.md)

## Tensions

- [Lazy Evaluation / Debuggability/Resource Lifetime](https://banes-lab.com/records/tension/debuggability-resource-lifetime-lazy-evaluation.md)
- [Lazy Evaluation / Eager Full Materialization](https://banes-lab.com/records/tension/eager-full-materialization-lazy-evaluation.md)

## Severity

- [contextual](https://banes-lab.com/records/vocabulary/severity-contextual.md)

## Category

- [Streaming / Pipeline / Dataflow Processing](https://banes-lab.com/records/architecture-category/streaming-pipeline-dataflow-processing.md)

## Linked from

- [The direction axis](https://banes-lab.com/software-architecture/model/the-direction-axis.md)
- [Scalability / Performance / Optimization](https://banes-lab.com/ontology/principles/architecture-category-scalability-performance-optimization.md)
- [Streaming / Pipeline / Dataflow Processing](https://banes-lab.com/ontology/lexicon/lexicon-category-streaming-pipeline-dataflow-processing.md)
- [Severity levels](https://banes-lab.com/ontology/schema/the-vocabulary-severity.md)
- [The resolutions](https://banes-lab.com/ontology/schema/the-resolutions.md)

## Evidence in the code

- [registerPage](https://banes-lab.com/source/tree/domain/registries/page.registry.ts.md)
- [presentation/records](https://banes-lab.com/anatomy/tree/folder-presentation-records.md)
- [presentation/records/records.barrel.ts](https://banes-lab.com/source/tree/presentation/records/records.barrel.ts.md)
