perf: Cache SemanticModel and improve null handling in generators#1678
Conversation
…1572) - Cache GetSemanticModelAsync result in AsyncModuleCodeFixProvider to avoid duplicate async calls in the loop (fixes #1572) - Convert helper methods to static since they no longer need instance state - Make EscapeXmlComment and EscapeIdentifier accept nullable strings for consistent null handling (fixes #1639) - Return string.Empty instead of returning null from EscapeIdentifier 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryThis PR optimizes the AsyncModuleCodeFixProvider by caching the semantic model to avoid redundant async calls, and improves null safety in GeneratorUtils methods. Critical IssuesNone found ✅ SuggestionsAsyncModuleCodeFixProvider.cs - Consider CancellationTokenThe cached semantic model at line 64 doesn't pass the var semanticModel = await context.Document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);This is good - the cancellation token is properly threaded through. GeneratorUtils.cs - Behavioral Change in EscapeIdentifierThe change at line 163 modifies behavior:
This is technically a breaking change for callers expecting Suggested addition: /// <summary>
/// Escapes a C# identifier if it's a reserved keyword by prefixing with @.
/// Returns an empty string if the input is null or empty.
/// </summary>Verdict✅ APPROVE - No critical issues The performance optimization in AsyncModuleCodeFixProvider is well-implemented and the null safety improvements are beneficial. The behavioral change in EscapeIdentifier appears safe based on current usage patterns. |
Summary
Issues Fixed
Changes
Test plan
🤖 Generated with Claude Code