Skip to content

Clarify IOptionsSnapshot performance characteristics and pipeline recomputation (Fixes #53890) - #56662

Open
Manish-1kumar wants to merge 1 commit into
dotnet:mainfrom
Manish-1kumar:users/manish/issue-53890-ioptionssnapshot-perf-characteristics
Open

Manish-1kumar wants to merge 1 commit into
dotnet:mainfrom
Manish-1kumar:users/manish/issue-53890-ioptionssnapshot-perf-characteristics

Conversation

@Manish-1kumar

Copy link
Copy Markdown
Contributor

Fixes #53890

Summary of Changes

  • Adds a Performance considerations subsection under Use IOptionsSnapshot to read updated data in \docs/core/extensions/options.md.
  • Clarifies that \IOptionsSnapshot\ recomputes options on every new dependency injection scope by executing the full configuration, post-configuration, and validation pipeline.
  • Explains the implications for ASP.NET Core applications where DI scopes align with HTTP requests.
  • Provides architectural guidance on choosing between \IOptions, \IOptionsMonitor, and \IOptionsSnapshot, including strategies for reading current values without per-scope recomputation.

@dotnetrepoman dotnetrepoman Bot added this to the November 2026 milestone Nov 1, 2026
@dotnet-policy-service dotnet-policy-service Bot added dotnet-fundamentals/svc community-contribution Indicates PR is created by someone from the .NET community. labels Nov 1, 2026
@BillWagner
BillWagner requested a balanced review from Copilot November 25, 2026 16:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The guidance misstates monitor recomputation triggers by omitting explicit cache invalidation and needs to exclude scope-dependent options pipelines from monitor recommendations to avoid dependency-lifetime failures.

2 open issues
What changed in this PR

Clarifies IOptionsSnapshot<TOptions> performance in the .NET options-pattern guide, addressing #53890.

Changes:

  • Explains per-scope pipeline execution and its potential impact on HTTP request latency.
  • Adds guidance for choosing options interfaces and capturing monitor values for consistent per-scope access.
File Description
docs/​core/​extensions/​options.md Adds performance considerations, options-selection guidance, and an updated article date.

Review effort: Balanced

To select the right options abstraction for your scenario:

- **Static configuration**: If your configuration never changes after application startup, use <xref:Microsoft.Extensions.Options.IOptions`1>. It is a singleton service whose value is computed once for the entire application lifetime.
- **Reloadable configuration with high throughput**: If you need to observe configuration updates but want to avoid re-evaluating options on every request scope, use <xref:Microsoft.Extensions.Options.IOptionsMonitor`1>. `IOptionsMonitor` is a singleton service that caches options instances and only recomputes them when the underlying configuration source fires a change token notification.

- **Static configuration**: If your configuration never changes after application startup, use <xref:Microsoft.Extensions.Options.IOptions`1>. It is a singleton service whose value is computed once for the entire application lifetime.
- **Reloadable configuration with high throughput**: If you need to observe configuration updates but want to avoid re-evaluating options on every request scope, use <xref:Microsoft.Extensions.Options.IOptionsMonitor`1>. `IOptionsMonitor` is a singleton service that caches options instances and only recomputes them when the underlying configuration source fires a change token notification.
- **Consistent scope snapshots from an options monitor**: If your application requires a value that does not change during the execution of a single request, but you want to avoid per-scope recomputation, consider capturing <xref:Microsoft.Extensions.Options.IOptionsMonitor`1.CurrentValue> once at the start of the scope (such as in middleware) or registering a scoped service that resolves the current value from `IOptionsMonitor<TOptions>`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates PR is created by someone from the .NET community. dotnet-fundamentals/svc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: clarify IOptionsSnapshot<T> performance characteristics

2 participants