dotnet / dotnet/wpf

Unnecessary allocations in UIElementAutomationPeer of Matrix/Transform

Open
#10,678 2 comments 2 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

_Note that I will submit a PR in the coming days for this issue, so its more of an FYI._

### Description

`CalculateVisibleBoundingRect` attempts to perform an intersection out of matrix transformation from the AP owner to the parent, using matrix inversion. In most simple cases, there will either be identity matrix or just a standard matrix transform.

In the case displayed, `TrySimpleTransformToAncestor` returns a `Matrix`, which then inside `InternalTransformToAncestor` creates a `MatrixTransform`, which is forced to box this `Matrix`, just to immediately invoke `Inverse` property (inherited via `Transform` abstraction), which is then inverted and once again, a `MatrixTransform` is created and `Matrix` must be boxed.

All this can be special-cased with a few lines avoided and done on stack instead, which in this case would save around 800 MB, which is most of what this app has allocated.

### Showcase

![Image](https://github.com/user-attachments/assets/cf0b9212-1a0e-47da-a3a1-90721b702a28)

### 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.