Conversation
Cache the PropertyInfo lookup for the Disposables property using a ConcurrentDictionary keyed by Type. This avoids repeated reflection calls on every DisposeAsync invocation. Fixes #1473 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryCaches reflection lookup for the service provider's internal Disposables property to improve performance on repeated pipeline executions. Critical IssuesNone found ✅ SuggestionsConsider thread-safety of the cached PropertyInfo usage: While the ConcurrentDictionary safely caches the PropertyInfo lookup, the actual reflection access (GetValue(Services)) happens outside the cache. This is fine since PropertyInfo.GetValue is thread-safe, but it's worth noting that the Services instance could theoretically change between calls if service provider types differ across invocations. Reflection on internal implementation details: This code relies on accessing a private "Disposables" property of the service provider implementation. While the caching improves performance, the underlying approach is fragile - if the Microsoft.Extensions.DependencyInjection internals change, this breaks. Consider:
These are minor observations - the caching implementation itself is solid and the static lambda prevents allocations as intended. Verdict✅ APPROVE - No critical issues, solid performance optimization |
There was a problem hiding this comment.
Pull request overview
This PR introduces a performance optimization to the PipelineHost.DisposeAsync method by caching reflection lookups using a ConcurrentDictionary. The change avoids repeated reflection calls when accessing the internal Disposables property of the service provider.
Key changes:
- Added a static
ConcurrentDictionary<Type, PropertyInfo?>to cache property reflection lookups - Modified
DisposeAsyncto useGetOrAddwith a static lambda to retrieve cachedPropertyInfo - Extracted
Services.GetType()call to a local variable to improve readability
Summary
PropertyInfolookup for theDisposablesproperty using aConcurrentDictionary<Type, PropertyInfo?>keyed by service provider typeDisposeAsyncinvocationstaticlambda to prevent closure allocationFixes #1473
Test plan
dotnet build)🤖 Generated with Claude Code