Skip to content

Optimize export lookup and simple activation - #772

Draft
Andrew Arnott (AArnott) wants to merge 3 commits into
mainfrom
perf-optimizations
Draft

Optimize export lookup and simple activation#772
Andrew Arnott (AArnott) wants to merge 3 commits into
mainfrom
perf-optimizations

Conversation

@AArnott

@AArnott Andrew Arnott (AArnott) commented Aug 21, 2026

Copy link
Copy Markdown
Member

Summary

  • cache exact runtime export lookups and initialized shared root values
  • bypass general lifecycle state transitions for non-shared parts with no imports or OnImportsSatisfied callbacks
  • avoid LINQ and empty-array allocations while resolving constructor arguments through the existing reflection lifecycle
  • add BenchmarkDotNet coverage for shared, non-shared, constructor, property, complex, and ImportMany activation
  • document the investigation, JIT tradeoffs, compiled activation experiment, and staged hybrid-plan ideas in PERFORMANCE.md

This branch does not add expression-compiled constructors, setters, or activation plans. That experiment is preserved separately on perf/compiled-activation-plans and has no pull request.

Performance

Three-run median from the IocPerformance scenarios (single-threaded, 500,000 iterations):

Scenario MEF2 VS MEF Ratio
Singleton 135 ms 207 ms 1.53x
Transient 128 ms 1,277 ms 9.98x
Combined 198 ms 5,300 ms 26.77x
Complex 499 ms 21,288 ms 42.66x
Property 1,121 ms 21,378 ms 19.07x
IEnumerable 791 ms 11,729 ms 14.83x

Compared with the original VS MEF measurements, this is approximately 30x faster for shared retrieval, 7x faster for simple non-shared activation, and 1.4-2.6x faster for the imported graph scenarios. The much larger imported-graph gains and their additional JIT cost are isolated on the topic branch.

Validation

  • Microsoft.VisualStudio.Composition.Tests: 2,064 net8.0 and 2,107 net472 tests passed
  • benchmark project builds without warnings for net10.0 and net472
  • all six activation benchmarks execute under both target frameworks
  • no new expression compilation remains in the pull request diff

Validation pipeline

vs-mef validation build 15110883

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Document the activation performance investigation and retain only the non-expression optimizations on the active PR branch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AArnott Andrew Arnott (AArnott) changed the title Improve export activation throughput Optimize export lookup and simple activation Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant