What problem does it solve?
Public APIs that compute expensive data and then delegate to internal helpers can accidentally cause duplicate heavy work when the helper recomputes the same data. This pattern prevents wasted CPU and startup cost by letting callers supply pre-computed results while preserving backward compatibility for existing internal callers.
Core Features & Use Cases
- Optional parameter pattern: inner helpers accept an optional precomputed argument that defaults to null.
- Guarded computation: helpers use null-coalescing to compute only when the value is not provided.
- Type visibility guidance: promote sealed helper types to internal if they must appear in the public signature.
- Primary use case: expensive PowerShell runspace creation and session introspection where double initialization is costly.
- Responsibility model: the public API layer is responsible for computing and passing the precomputed data when available.
Quick Start
Compute the expensive data in the public method and pass it as the optional parameter to the inner helper to avoid duplicate work.