dotnet / dotnet/wpf

Unnecessary allocations in UncommonField<T> for bool

Open
#10,677 0 comments 0 reactions 1 assignee Claimed by @h3xds1nz View on GitHub
:construction: work in progress 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

#4220 attempted to fix this problem but it completely changed the behaviour and so it was reverted (plus, it won't really fix the problem as the values then get boxed during insertion anyways (and it won't prevent insertion due to the fact that most paths are inserting `true` and default is `false`)).

Before it was reverted, in #6528, Stephen added boolean path (it gets compiled only for the `bool` generic paths) which solves the problem for insertions as well, but during the reversal in #7426 this was made useless once again, because you now box during `ReferenceEquals` check, so that optimization is pointless.

My repro is for UIA but the same will occur for HiearchicalVirtualization for example (see #4114).

### Showcase

![Image](https://github.com/user-attachments/assets/24b6ce80-b8a8-4388-9426-9e0ffa28aeb6)

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