Eager vs lazy
Description
A scheduling choice that recurs across systems wherever there’s work and a question of when to do it: eager strategies do the work upfront and store the result (fast on later access; may compute work that’s never consumed); lazy strategies defer until the result is actually needed (slower on the first access; only compute work that’s called for). The same structural choice runs across CS subfields — call-by-need vs call-by-value in functional programming, demand paging vs prefetching in operating systems, materialized views vs computed views in databases, eager loading vs lazy loading in ORMs, prefetching vs request-driven fetching on the web, just-in-case vs just-in-time inventory. The diagnostic question — “is the cost of computing-and-not-using cheaper or more expensive than the cost of blocking-the-consumer?” — is the load-bearing tradeoff. Eager wins when consumer-latency is critical and computation is cheap relative to the chance it’ll be used. Lazy wins when computation is expensive and consumption is sparse or unpredictable.Triggers
User-initiated: User asks “should we compute X now or wait?” or describes a strategy choice between upfront vs deferred work. Vocabulary cues: “eager,” “lazy,” “precompute,” “on-demand,” “prefetch,” “speculation,” “JIT,” “AOT,” “materialize.” Agent-initiated: Agent notices a system has the choice between paying compute-cost upfront vs paying consumer-latency-cost later. Candidate inference: “what’s the cost asymmetry; what fraction of precomputed work would actually be used?” Situation-shape signals: Caching discussions. Performance-tuning decisions about precomputation. Storage-vs-computation tradeoff conversations.Exclusions
- Forced-eager domains — real-time embedded systems where the consumer cannot wait; the strategy choice is foreclosed by requirements.
- Forced-lazy domains — work that requires unknown-future inputs; cannot be precomputed in principle.
- Pure pull or pure push systems — when the architecture commits to one shape (everything is a pull request; everything is a fire-and-forget event), the strategy choice is at the architecture level, not the per-work level.
Structure
Relationships
- cost-cascade — eager-vs-lazy is cost-cascade applied to time: cheap-precomputed-default vs expensive-on-demand-fallback (or vice versa, depending on which strategy is the system’s primary mode).
- gradient — the choice is rarely binary; speculative prefetch, lazy-with-cache, partial materialization sit at intermediate points along the eager↔lazy gradient.
- load-bearing — diagnostic for evaluating eager strategies: what fraction of precomputed work is load-bearing (actually consumed)?
- asymmetric-gate — choosing eager vs lazy is often choosing which direction is cheap and which is expensive at the strategy boundary.
- trigger-rule-pair — lazy strategies need a clear trigger condition (when is the deferred work invoked?); without it, the deferral becomes loss.
Examples
JIT vs AOT compilation · computer-science
JIT vs AOT compilation · computer-science
Lean manufacturing: just-in-time inventory (Ohno 1988) — eager-vs-lazy applied to physical supply chains. · business
Lean manufacturing: just-in-time inventory (Ohno 1988) — eager-vs-lazy applied to physical supply chains. · business
Cache warming · computer-science
Cache warming · computer-science
CPU branch prediction · computer-science
CPU branch prediction · computer-science
Database indexes · computer-science
Database indexes · computer-science
Databases: materialized views (Gupta & Mumick 1995) vs computed views; the materialization-view tradeoff has its own literature on incremental view maintenance. · computer-science
Databases: materialized views (Gupta & Mumick 1995) vs computed views; the materialization-view tradeoff has its own literature on incremental view maintenance. · computer-science
Functional programming: lazy evaluation in Haskell (Hughes 1989, "Why Functional Programming Matters"); call-by-need semantics as the canonical language-design instance of lazy evaluation. · computer-science
Functional programming: lazy evaluation in Haskell (Hughes 1989, "Why Functional Programming Matters"); call-by-need semantics as the canonical language-design instance of lazy evaluation. · computer-science
Operating systems: demand paging vs prefetching; cache replacement policies (LRU, LFU as ranked-lazy). · computer-science
Operating systems: demand paging vs prefetching; cache replacement policies (LRU, LFU as ranked-lazy). · computer-science
React rendering · computer-science
React rendering · computer-science
Test suites · computer-science
Test suites · computer-science
Web performance: prefetch / preload / preconnect (W3C resource-hints spec) is the eager strategy library. · computer-science
Web performance: prefetch / preload / preconnect (W3C resource-hints spec) is the eager strategy library. · computer-science