-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Improve PropertyMapper performance #28077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve PropertyMapper performance #28077
Conversation
src/Core/src/PropertyMapper.cs
Outdated
// when we call UpdateProperties | ||
HashSet<string>? _updateKeys; | ||
IReadOnlyDictionary<string, Action<IElementHandler, IElement>>? _mergedMappers; | ||
IReadOnlyDictionary<string, Action<IElementHandler, IElement>> MergedMappers => _mergedMappers ?? SnapshotMappers().Mappers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is OrderedDictionary
in .NET 9 and I wonder if it is useful here or somewhere else.
(I wanted to take a look at "ordering of mapper calls" for a very long time. Mostly to make sure that a wrapper view is created by the very first mapper call. I'm very happy that you beat me in working on this. :))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That one is not generic, so it comes with the cost of casting everything, and I also think it has a cost in performance compared to the generic implementation.
That said, we'd have to change _mapper
too in that case (which is a public API unfortunately), or add an additional List<string> _keys
property to use while inserting new mappers.
I think we can safely bet on this given it's covered by unit tests, if it changes we can switch to something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified the link. It's generic.
Anyway, it's fine by me. I just wanted to mention that the ordered variant exists now. If it used or not, it's not as relevant as if all design choices were considered.
f0c1756
to
7b1bc2b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is late, and I am reviewing with my brain turned off. But I got some questions that maybe I wouldn't have asked in the morning. But the PR looks nice.
7b1bc2b
to
f255038
Compare
@mattleibow I've updated the PR, including the fix for the broken tests: I was totally missing the special Also I backported the race-condition fix on iOS |
{ | ||
foreach (var key in _mapper.Keys) | ||
// When doing the initial properties batch updates, ignore properties in the skip list. | ||
// These will be handled by ViewHandler.SetVirtualView() instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Azure Pipelines successfully started running 3 pipeline(s). |
src/Core/tests/Benchmarks/Benchmarks/PropertyMapperBenchmarker.cs
Outdated
Show resolved
Hide resolved
f255038
to
bf03d95
Compare
Note: these failing tests are unrelated:
See more at: #28125 |
d06c4c8
to
4395e1f
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
4395e1f
to
7762a08
Compare
/azp run |
03f142c
to
b42a518
Compare
@mattleibow so I had to refactor the code again due to the The introduction of that class changed the meaning of
to something like:
This is really unfortunate because now there's no way to tell what are the defined keys. Initially I thought of simply moving the skip list into On top of that, if the user ever wanted to define their own I've added unit tests to cover these scenarios. #27259 will enable us to detect when we're running the initial mapping, so we will be able to remove
This way the user can even define their own mappers ensuring they will be executed on the first mapping. |
b42a518
to
6ee08fc
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
6ee08fc
to
bd51dc1
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Failing tests look unrelated:
|
/rebase |
bd51dc1
to
475b7b3
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
|
Description of Change
PropertyMapper
performance by caching mappers (same thing is currently done on mapper's keys)viewHandler.CanInvokeMappers()
check toUpdateProperties
level considering that on Android this method method uses the Java objectMapToolbar
depends onMapFlyout
) and formally solves them by setting the right order of executionBenchmarks
Before
After