precomputed-optional-parameter

Accept optional precomputed parameters to avoid duplicate expensive computations.

9|1|Updated Jul 21, 2025
One-click install
npx skills add https://github.com/usepowershell/PoshMcp --skill precomputed-optional-parameter
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: precomputed-optional-parameter
Source: https://github.com/usepowershell/PoshMcp/tree/main/.squad/skills/precomputed-optional-parameter
Command: npx skills add https://github.com/usepowershell/PoshMcp --skill precomputed-optional-parameter

SYSTEM DOCUMENTATION & REQUIREMENTS

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.

Frequently Asked Questions about precomputed-optional-parameter

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I avoid redundant expensive computation in C# public APIs?▼

Avoid redundant expensive computation by passing pre-computed results to internal helper methods as optional parameters. This pattern allows public APIs to delegate execution without triggering duplicate heavy work, preserving backward compatibility for existing internal callers.

What is the C# optional parameter pattern for precomputed values?▼

The optional parameter pattern for precomputed values involves inner helpers accepting a nullable argument that defaults to null. Helpers use null-coalescing guards to compute the data only when the caller does not provide a precomputed value.

How do I optimize PowerShell runspace initialization performance in dotnet?▼

Optimize PowerShell runspace initialization by passing precomputed session introspection data to delegation methods. This prevents the inner helper from triggering a second costly runspace creation during its own initialization phase.

How to maintain backward compatibility when adding precomputed parameters to sealed inner types?▼

Maintain backward compatibility by adding optional precomputed parameters with null defaults to existing method signatures. Promote sealed inner helper types to internal visibility if they must appear in the public API signature.

When should I use null-coalescing guards for expensive data computation?▼

Use null-coalescing guards for expensive data computation when a public method computes heavy data and delegates to an inner helper. The guard ensures the helper computes the data only if the caller passes a null precomputed parameter.

What is the best way to prevent duplicate work in nested C# helper methods?▼

The best way to prevent duplicate work in nested C# helper methods is establishing a responsibility model where the public API layer computes and passes the expensive data. The inner helper uses null-coalescing to process the provided value or recompute it.