winforms icon indicating copy to clipboard operation
winforms copied to clipboard

Refactor `IArrangedElement` to remove `PropertyStore` usage

Open elachlan opened this issue 1 year ago • 4 comments

This is part of the effort to refactor winforms to remove PropertyStore and move to fields.

Related: #9508

I reviewed the layout classes (DefaultLayout/FlowLayout/TableLayout) as well as CommonProperties and moved any of the PropertyStore usages to properties on IArrangedElement. For the values that made use of the BitVector32 LayoutState, I did not expose individual properties, as the logic was able to be centralized in CommonProperties.

The properties from FlowLayout were merged into the BitVector32 LayoutState to reduce memory usage.

Using winforms test the memory usage was:

Before After
573.41Kb 574.42Kb
Microsoft Reviewers: Open in CodeFlow

elachlan avatar Feb 01 '24 11:02 elachlan

Codecov Report

Attention: 41 lines in your changes are missing coverage. Please review.

Comparison is base (7c65507) 72.64233% compared to head (e67f044) 72.54055%. Report is 72 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #10788         +/-   ##
===================================================
- Coverage   72.64233%   72.54055%   -0.10179%     
===================================================
  Files           2906        2927         +21     
  Lines         622319      619987       -2332     
  Branches       46906       46923         +17     
===================================================
- Hits          452067      449742       -2325     
+ Misses        161918      161898         -20     
- Partials        8334        8347         +13     
Flag Coverage Δ
Debug 72.54055% <81.01852%> (-0.10179%) :arrow_down:
production 43.49331% <81.01852%> (+0.04554%) :arrow_up:
test 97.32357% <ø> (-0.01968%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

codecov[bot] avatar Feb 01 '24 13:02 codecov[bot]

Hiya - whats the rationale here? Just curious

hughbe avatar Feb 01 '24 17:02 hughbe

@hughbe hi, it started as an investigation in making PropertyStore generic to help improve the code and reduce bugs. It was quickly realized that PropertyStore was overly complex for no reason and it looked like we could greatly simplify it, by using a generic dictionary. Then after working on that we started to investigate if it was even worth having a PropertyStore at all. Since having a backing field doesn't dramatically add to memory usage and allows for greater compiler optimisations.

It's been a journey for sure.

elachlan avatar Feb 01 '24 21:02 elachlan

I need to spend some time chatting with @KlausLoeffelmann and @lonitra about this. I'll circle back sometime next week hopefully.

JeremyKuhne avatar Feb 09 '24 19:02 JeremyKuhne

@JeremyKuhne any chance you managed to have discussions about this yet?

elachlan avatar Mar 19 '24 22:03 elachlan

@elachlan Thanks for pinging me. We've had some more critical work come up, so we haven't had time yet unfortunately. I'm not sure when we'll get a chunk of time at the moment.

JeremyKuhne avatar Mar 20 '24 00:03 JeremyKuhne

@elachlan sorry things got thrown off with BinaryFormatter work. Going to tackle early in .NET 10 and @lonitra will work on this as well. I'll look at bringing in my Value class to handle attached properties without boxing- that way we can use a single dictionary.

JeremyKuhne avatar Jul 11 '24 19:07 JeremyKuhne