-
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 working with EllipseGeometry/RectangleGeometry, reduce allocs #9981
base: main
Are you sure you want to change the base?
Conversation
…tatic byte fields into constants
@h3xds1nz What are you doing with all these micro optimization PRs?
I hope you have discussed all this with Microsoft ahead of time because it looks very strange from my viewpoint. If you want to focus on performance, great! But DO NOT spam a bunch of micro optimization PRs that risk breaking already working code. Focus on the bigger gains. |
src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/EllipseGeometry.cs
Show resolved
Hide resolved
@robert-abeo I wasn't originally even gonna respond, but here you go.
There are sometimes But guess what, shocker, most of the time, the conventions vary not just in a namespace, but in a single file, and in the particular file (EllipseGeometry.cs) where you've highligted the line 72; I'd recommend checking line 360; 205; 157 (original lines, those were not edited since that part of WPF was opensourced), and tell me, please, what is the coding style? Why are those function definitions as long as the particular If we wanna have a look at so called "Microsoft's standard code format rules", guess those would be mostly incorporated in standard tools such as Visual Studio and Roslyn analyzers, correct? You obviously weren't thinking about incorporating random Rider rules and line breaks for 1024x768 CRT monitors, calling them current "Microsoft's standard code format rules"? Plus there's of course runtime coding style which I can't really seem to have violated. https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/coding-style.md Not even in C code bases you'd see auto formatters mostly to wrap 1 per line. Plus, as of like 4 years ago, there's
And yes, it is absolutely fine to put parameters onto the next line when a single one gets too long! Lastly, given the time and effort you must have put into your two comments, you could have put up PRs fixing half of your Fluent-styling issues instead and attempt to help everyone using WPF's new Fluent theme for a much better experience incorporating it into their applications. I'd even give you a thumbs up as it shows effort! But I understand, it is always easier to randomly criticise from distance. Please, instead of responding to my reaction here, I'd recommend creating a discussion, name it "Performance optimizations PRs should be banned as the team has not been 100% focused on the issues I have created" if you want and have a go at it. But I shall not take this from a drive-by shooter. Fixing community-reported bugs and alongside doing some optimizations does not make me the ultimate authority but it surely gives me more ground to have an educated opinion on this, and given your inability to even go through one file before saying how I've violated the codestyle that's violated 15 times in that file to begin with, it definitely doesn't hold a high value to me as a constructive feedback. I couldn't be more constructive, simply because, well, I "focus on bigger gains" but without preparing the ground at the down level, with PRs like these, you can never get there. One last example, let's see if you can comprehend it: With that being said, I'll continue on "spamming" when I feel like it unless the team's position is to close my PRs, thank you. There's 1.2k open issues and for about 80% of what I'm submitting it is contributing to fixing those issues but since it is only partially as the fixes require ground preparation often times, it does not justify slapping "Fixes #" on it. |
I agree with some of what @robert-abeo said, though I really disagree with the tone used. I'll open an issue to discuss revamping contributor guidelines but I'll leave some thoughts here: For now, I'll say that I'm in favor of the performance enhancement in this PR but I'm against the unrelated changes around it. In my experience, this PR would have been refused in a lot of other repos (And probably in dotnet/runtime and WPF follows most of the guidelines of dotnet/runtime). Here's some things I noticed:
The last bullet point here says "DO NOT submit pure formatting/typo changes to code that has not been modified otherwise." so technically some of the code in this PR is against the guideline. This is a very old and very big code base, you'll find code that you would've written differently than what was written 10 years ago and you'll find code in the future that you would've written differently than what was written today. I'm not trying to discourage you from contributing since your PRs are valuable, I'm just trying to make sure they are done in the best way possible. |
I criticized other people for mixing actual changes and formatting changes in the past, in much smaller PRs, because it makes it difficult to review (I particularly remember one that could have been single change but was a few extra lines with formatting changes, with which the team agreed and asked the author to only do the functional change, though I cannot seem to find that PR now), so it sounds fair to uphold that view: Yes, I would certainly prefer if we could keep styling changes to minimum, preferably matching the code around. The repercussions from my side, however, is probably just unwillingness to spend time reviewing PRs (which otherwise tend to be straightforward in case of @h3xds1nz). But I also agree that the team is free to do what they see fit. So far these PRs seem to be getting merged. Moreover, it was indicated that performance contributions are now a priority: #9920. I wouldn't want to lose contributors like @h3xds1nz by making what they do not enjoyable, so I hope we can find some balance between what the team is willing to accept and authors to produce while allowing reviewers to help out. |
A few more points.
|
This is such an unhelpful comment. If you have concerns about specific code changes and their ramifications, by all means, please name them, that's actually very helpful for everyone involved. But if you don't actually have anything to contribute, maybe refrain from discouraging people who actually contribute from contributing. Thankfully, you don't seem to be in a position to decide (micro) optimizations are not needed, and people who actually get to decide those things have been merging those changes, that probably should have been your cue about the fact that your view about micro optimizations is not shared by others, especially by those who actually get to decide those things.
"Every change involves some risks, so we will avoid micro optimizations" is certainly not a Microsoft policy. 200+ pages long |
Just very recently for example; #9882 - nobody said a thing. All those null-conditional access operators instead of if-checks, changes to the property styles, all it could have been was removing
Guess we're gonna see some stylistic changes from Jeremy in the parts he touches. Some picks from the PR but there's about 400 of unrelated style changes (null-conditional is the same IL): @ThomasGoulet73 Have you been to Winforms repo? https://github.com/dotnet/winforms/pull/11852/files And there's around hundreds of PRs that are just "simplify"; because format has already been done. Terrifying, indeed. There's one fundamental differences between runtime - WF (or even aspnetcore) and WPF, that is; WPF ain't formatted, like at all. It didn't get any global polishing unlike other repos. You have statements that are in the middle of the screen and then 1 line put fully to the left. No consistency. So yes, it's super easy to "make" those changes.
Well it's easy to comfort that rule because when you press auto format, nothing changes, since the codebase has been consistently formatted, isn't it. And there aren't 200 suggestions on how to change the code with newer features (that you're accustomed to writing most of the time) because they're incorporated already. I don't do this part because I enjoy it; I do it in smaller files so I can orient in the code. And I cannot stress how many times I just press It takes 300 lines for 4 functions, the function And then you can finally understand and remember/see what it does without scrolling up and down. Writing short and oriented functions/procedures is not just about principle but also about readibility. Oh and this function of 22 lines? Tell me what is the edge case. None actually. You bet I'd rewrite it in 10 (or 6, if you remove the braces), so you don't have to think about it: private static void CollectTrailingSpaces(List<SimpleRun> runs, TextFormatterImp formatter, ref int trailing, ref int trailingSpaceWidth)
{
for (int i = runs.Count - 1; i >= 0; i--)
{
if (!runs[i].CollectTrailingSpaces(formatter, ref trailing, ref trailingSpaceWidth))
{
break;
}
}
} I have per the team's earlier suggestion put the changes into different commits, and simply going commit-by-commit, there's not really a difference in the reviewing experience imho, I always review it myself (but obviously that's not a clear view) - here I'm happy @ThomasGoulet73 you've suggested to use @miloush the PR on your mind was #7910 I guess, I've seen it recently as I was correcting the other event args. Hugh did a lot of changes in cleaning up certain parts of System.Xaml after it was opensourced, those files are way better experience than the spaghetti code around Lastly, I'd be happy to do the same thing WF and runtime did (address formatting and newer compiler features etc. globally) to reduce noise in perf PRs if its discussed properly with the community and the team. It would make my life easier (and anyone else's contributing) as well to not have to care about those things, that's a sure bet. It would get the codebase to a much better state too. |
It would certainly help some contributors and avoid all discussions if we introduced an .editorconfig and formatted the whole repo at once. @pchaurasia14 any thoughts on that? I am less keen on renaming things without good reason, it makes it difficult to track things across versions and does have the potential to break applications without good reason. Obviously using reflection is explicitly not supported, but we should have a reason to break it more than a personal preference or code style. |
Your responses are extremely long but don't seem to acknowledge even an understanding of my points. I'll avoid any more personal comments. So I'm just going to say this is a fundamental difference of opinion and we won't be able to resolve it. I stand by my comments that I would not approach these PRs anything like what you are doing for the reasons stated. Microsoft historically has been very careful of unnecessary change so as not to break anything once a product is so old and widely used. The WPF team also has very limited resources. It's up to the maintainers to continue or let go the discussion. |
Your observation is correct, I did not react to you this time. And I shall not, @rampaa has said it for me. |
Description
Removes some unnecessary
gen0
allocations when working withEllipseGeometry
/RectangleGeometry
(such as adding them to aPathGeometry
or combining geometries which serializes them (Point
array alloc) and when renderingTickBar
. Also introducesinternal
constructors forPathFigure
/PathGeometry
that can be used with inline arrays.Also changes some
private static
fields to constants, decreasing static allocations.The savings are not that massive right now, but it will allow for further optimizations (and there's a lot of space for it).
Define geometry, add to group, get bounds
Benchmark code
Customer Impact
Improved performance, decreased allocations.
Regression
No.
Testing
Local build, sample apps, usage of types.
Risk
Should be low, all the changes were done with using stack-allocated memory
Microsoft Reviewers: Open in CodeFlow