Skip to content

Make comhost cache COM activation delegate info#130498

Merged
elinor-fung merged 6 commits into
dotnet:mainfrom
elinor-fung:comhost-cache-activation-delegate
Jul 11, 2026
Merged

Make comhost cache COM activation delegate info#130498
elinor-fung merged 6 commits into
dotnet:mainfrom
elinor-fung:comhost-cache-activation-delegate

Conversation

@elinor-fung

@elinor-fung elinor-fung commented Jul 10, 2026

Copy link
Copy Markdown
Member

DllGetClassObject resolved the COM activation delegate on every call, which loaded hostfxr, parsed the app's runtimeconfig.json, and created a new secondary host context each time.

Since the inputs (the comhost path and runtimeconfig) for getting the activation delegate and load context should not change, we can just do this once per comhost. This changes comhost to get the activation delegate once and cache it for the process lifetime.

cc @dotnet/appmodel @AaronRobinsonMSFT @batzen

Fixes #130251

DllGetClassObject resolved the COM activation delegate on every call, which
loaded hostfxr and parsed the app's runtimeconfig.json (creating a new
secondary host context) each time. For applications that create COM objects
implemented in .NET in a tight loop this is a significant, repeated cost.

Resolve the activation delegate once and cache it for the process lifetime
(the runtime is never unloaded). Failures are not cached, so a transient
failure is retried on the next activation. This reduces the per-activation
runtimeconfig.json parsing from once per call to once per process.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Pull request overview

This PR changes comhost’s DllGetClassObject path to resolve the COM activation delegate once and cache the activation state (app path, delegate pointers, and load context) for reuse, instead of reloading hostfxr and re-parsing configuration on every activation.

Changes:

  • Added a cached com_activation_info and a get_com_activation_delegate helper that initializes the activation delegate once and returns cached state on subsequent calls.
  • Updated DllGetClassObject to use the cached activation state when invoking the runtime activation delegate.
Show a summary per file
File Description
src/native/corehost/comhost/comhost.cpp Introduces process/module-lifetime caching of COM activation delegate info and switches DllGetClassObject to use it.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread src/native/corehost/comhost/comhost.cpp Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 16:46
Comment thread src/native/corehost/comhost/comhost.cpp Outdated

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.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread src/native/corehost/comhost/comhost.cpp Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 17:34

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.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment thread src/native/corehost/comhost/comhost.cpp Outdated
Comment thread src/native/corehost/comhost/comhost.cpp Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 17:45

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.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread src/native/corehost/comhost/comhost.cpp Outdated
Comment thread src/native/corehost/comhost/comhost.cpp Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 20:48

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.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread src/native/corehost/comhost/comhost.cpp Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 20:55

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.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new

@elinor-fung

Copy link
Copy Markdown
Member Author

/ba-g wasm failures are #129849

@elinor-fung elinor-fung merged commit 26b9008 into dotnet:main Jul 11, 2026
169 of 175 checks passed
@github-project-automation github-project-automation Bot moved this to Done in AppModel Jul 11, 2026
@elinor-fung elinor-fung deleted the comhost-cache-activation-delegate branch July 11, 2026 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

DllGetClassObject on comhost is extremely slow

4 participants