Skip to content

Optimize runtime, analyzer, and generator hot paths - #366

Merged
kzu merged 2 commits into
mainfrom
perf/phase-2-performance
Nov 29, 2026
Merged

kzu merged 2 commits into
mainfrom
perf/phase-2-performance

Conversation

@kzu

@kzu kzu commented Nov 29, 2026

Copy link
Copy Markdown
Member

Phase 2 of the codebase audit improvements: runtime, analyzer, and source generator performance optimizations.

Runtime hot paths

  • Cache \ParameterInfo[]\ and by-ref/out metadata per \MethodBase\ in \MethodMetadata\ to avoid repeated \GetParameters()\ array allocations across \MethodInvocation, \ArgumentCollection, \MethodReturn, and \DefaultValueBehavior.
  • Back \ArgumentCollection\ with a flat \Argument?[]\ array and a lazy name dictionary (only allocated when \Parameters.Length > 8), and pass arrays directly from \ArgumentCollection.Create.
  • Add generic \ValueConversion.Validate\ to eliminate value-type boxing in \Argument.
  • Make \MethodInvocation.Context\ and \SkipBehaviors\ lazy, skip \MethodReturn.GetOutputs\ allocations when no by-ref/out parameters exist, and skip \DefaultValueBehavior\ output rebuilding when no \out\ parameters exist.
  • Optimize \CompiledStuntFactory\ (\ConcurrentDictionary\ registry, zero-allocation single-type \TypeSet, parameterless fast-path, and cached constructor resolution per argument-type signature), \DefaultValueProvider\ (cached \Task.FromResult, \ValueTask, and \Queryable.AsQueryable\ factories), and \DynamicStuntInterceptor.
  • Cache \MethodBase.GetCurrentMethod()\ in per-member \private static MethodBase\ fields in \CSharpRewrite\ and \DelegateScaffold.

Analyzer & generator hot paths

  • Remove the dead no-op \PointerMemberAnalyzer\ while keeping \ST005\ reserved in \StuntDiagnostics.
  • Cache \StuntClosure.IsGenerator\ by \OriginalDefinition\ and replace the global \lock (sync)\ with \ConcurrentDictionary\ caches and per-call cycle detection.
  • Cache \LanguageVersion\ \PropertyInfo\ per \ParseOptions\ type in \RefStructHolders.
  • Pre-collect assembly registration attributes once per compilation in \UnsafeSignatureAnalyzer\ and remove LINQ delegate allocation in \SyntaxOnlyProcessorAnalyzer.
  • Replace prior generated syntax trees via \ReplaceSyntaxTree\ in \SyntaxProcessorDriver\ instead of accumulating duplicate partial trees across phases.
  • Parallelize default-interface helper generation in \StuntGenerator.
  • Index active overridable members by name in \INamedTypeSymbolExtensions.GetOverridableMembers\ (keeping the class public).
  • Replace all-at-once in-memory cache clearing in \StuntCache\ with LRU eviction down to 75% of budget plus periodic disk mtime refresh on memory hits.

Verification

  • Full solution build (\dotnet build /p:UseSharedCompilation=false -m:1, 0 errors).
  • Full test suite (\dnx --yes retest -- --no-build, 450/450 passed, including new \Phase2PerformanceTests).
  • \dotnet format whitespace\ and \dotnet format style\ verified on all modified files.

This pull request was created by CodeAlta.

Phase 2 performance improvements:
- Cache MethodBase parameter/by-ref metadata and switch ArgumentCollection to a flat array with lazy name dictionary
- Remove value-type boxing in Argument<T> validation, make MethodInvocation.Context/SkipBehaviors lazy, and skip empty outputs/out-parameter rebuilds
- Cache CompiledStuntFactory constructors and optimize TypeSet, cache DefaultValueProvider async/queryable factories, and streamline DynamicStuntInterceptor
- Emit per-member static MethodBase caches in generated stunts and delegate stunts
- Delete dead PointerMemberAnalyzer (keep ST005 reserved), make StuntClosure lock-free with cached IsGenerator, cache RefStructHolders reflection, pre-index UnsafeSignatureAnalyzer assembly registrations, remove LINQ closure in SyntaxOnlyProcessorAnalyzer
- Use ReplaceSyntaxTree in SyntaxProcessorDriver, parallelize default-interface helpers, index GetOverridableMembers by name, and add LRU eviction + disk mtime refresh to StuntCache

Co-authored-by: CodeAlta <noreply@codealta.io>
@kzu kzu added the enhancement New feature or request label Nov 29, 2026
@kzu
kzu enabled auto-merge (rebase) November 29, 2026 19:40
…structor for Native AOT

Co-authored-by: CodeAlta <noreply@codealta.io>
@kzu
kzu merged commit 46491e3 into main Nov 29, 2026
7 checks passed
@kzu
kzu deleted the perf/phase-2-performance branch November 29, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant