Skip to content

Unnecessary allocations in UIElementAutomationPeer of Matrix/Transform #10678

@h3xds1nz

Description

@h3xds1nz

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

Repro

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

https://github.com/h3xds1nz/UIAPerformancePitfalls

Metadata

Metadata

Assignees

Labels

PerformancePerformance related issue

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions