dotnet / dotnet/wpf

Invoke in ElementUtil and ElementProxy cause unnecessary delegate allocations

Open
#10,679 1 comment 3 reactions 1 assignee Claimed by @h3xds1nz View on GitHub
Performance
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

_I might bundle this up with some Dispatcher improvements to support generic invocations at least for internal use, so it would be a bigger PR. We will see, won't be right away._

### Description

The `Invoke` method from `ElementUtil` is causing unnecessary allocations due to the attempt to catch exceptions from another thread (if invoked on) and re-throw on the current thread. This further comes the from already allocating delegates inside `ElementProxy` that use this `Invoke` exclusively.

### Showcase

![Image](https://github.com/user-attachments/assets/353dad78-c91f-497b-a338-1cf7a7becf9e)

### Repro

Note: This repro is specifically crafted to highlight an issue like this.

https://github.com/h3xds1nz/UIAPerformancePitfalls

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.