-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Optimize PixelFormat creation and PixelFormatConverter conversion speed #9861
Conversation
ee8574c
to
db938d8
Compare
Resolved merge conflicts 03 |
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.
Overall LGTM.
@h3xds1nz, can you please address the minor comments and resolve the conflicts.
src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PixelFormat.cs
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PixelFormat.cs
Outdated
Show resolved
Hide resolved
db938d8
to
db9e3c2
Compare
@harshit7962 Conflicts resolved, convos addressed; one more thing: Per my last point in description (now strikethrough) and our conversation with Thomas in #9860, I've decided to wrap the masks returned in |
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.
Re-approving
Thanks @h3xds1nz for the contribution and quick follow-ups. |
@harshit7962 Thank you, happy to help! |
Description
PixelFormat
is a mutable struct, so we cannot really make itreadonly
if we don't want to incur performance degradation during creation of one; however several non-mutating method and members shall be madereadonly
to prevent defensive copies in those cases, and to improve code quality. This is not a breaking change.Guid
andstring
internal constructors up to two times.PartialList
wrapper since it doesn't really make sense because the array ownership goes to the caller.Same as Redefine PixelFormatChannelMask as readonly struct, optimize methods #9860, the difference being that theIList<PixelFormatChannelMask>
wrapper now will allow setting/mutating the array via indexer, whilePartialList<PixelFormatChannelMask>
would throw an exception previously, so you would have to explicitly go and create new array if needed.I do not think it matters, the array is owned by the caller as we make a private copy upon retrieval.PixelFormatChannelMask[]
cannot be NULL when returned from the getter, so the behavior is also unchanged.ReadOnlyCollection<T>
as the more lightweight and universal wrapper."Cmyk32" (string ctor)
Prgba128Float (string ctor)
WICPixelFormat128bppPRGBAFloat (Guid ctor)
WICPixelFormat64bppRGBHalf (Guid ctor)
Customer Impact
Improved performance, decreased allocations, cleaner codebase.
Regression
No.
Testing
Local build, playing with the struct.
Risk
Low, don't think anyone would dare to depend on the behavior of an internal type -
PartialList
that wraps the array, which is to throw an exception when trying to set any members of the underlying array. Such use case feels rather weird.Microsoft Reviewers: Open in CodeFlow