Update PropertyValues in TriggerBase/FrameworkElementFactory via reference #10003
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds ability to retrieve elements via
ref
fromFrugalStructList<T>
and the underlying storage formats, allowing for future optimizations. I intentionally did not modify the indexer as this can be done easily later on, so there's a new method for it now, which will allow for incremental optimizations in future on another types, where it makes sense and is safe to do so.This allows us to update items via reference, which is particularly useful in case of
PropertyValues
used inTriggerBase
andFrameworkElementFactory
since it is a struct that needs to be copied everytime on update back and forth.It is particularly efficient optimization here since the struct is full of managed pointers and ain't blittable, which takes considerable time to track back and forth for a simple update on one property.
I've also updated the getter/setter on
FrugalStructList<T>
for a minor speed boost, since it is used in almost every WPF collection, every branch counts. Nothing extra new, this is used inList<T>
by default for several releases.Original getter/setter prolog:
New getter/setter prolog:
Updating PropertyValues before/after
Minimal benchmark code
Customer Impact
Increased startup performance mostly, but also when dynamically creating triggers at runtime and obviously everything related to ContentPresenter, Validation, ItemsControl templates etc. I could observe about several milliseconds improvement with a simple app with a few controls with ScrollViewer (ListBox) etc.
Regression
No.
Testing
Local build, sample apps testing with styles/triggers to check they're applied property.
Risk
Low-to-medium, reviewers shall check that the
ref
is not forwarded/used anywhere while theFrugalStructList<T>
could be modified (this really means when Grow or for example Remove happens), R/W operations via indexer do not matter as they do not modify the backing store in size/copy it.Microsoft Reviewers: Open in CodeFlow