Skip to content

Conversation

@JimBobSquarePants
Copy link
Member

@JimBobSquarePants JimBobSquarePants commented Oct 16, 2020

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Fixes #1204

From conversations with the .NET Native team. Thanks @Sergio0694 for arranging that.

the crash happens while compiling CdfApplicationRowOperation.Invoke. I’m unclear what the best workaround would be. You can always place a NoOptimization flag on the method and that will probably get rid of the issue because the optimizer won’t be involved. From what I see on the stack, the optimizer is trying to hoist some operation out of the loop when it hits the problem.

The compiler actually fails unless both CdfApplicationRowOperation.Invoke and GrayscaleLevelsRowOperation.Invoke are marked with MethodImplOptions.NoOptimization.

I attempted to work around the problem by manually inlining the luminance method call and better managing scope per loop iteration. While this didn't work they should result in better performance across all platforms.

I've also added notes for potential further operations.

Proof

@JimBobSquarePants JimBobSquarePants added this to the 1.1.0 milestone Oct 16, 2020
@JimBobSquarePants JimBobSquarePants changed the title Disable NetNative optimization on UWP. Fix ARM Build for UWP Release Oct 16, 2020
@Sergio0694
Copy link
Member

Hey, this is awesome! 🎉🎉🎉

I mean, I'm sad to see that at the end of the day this build error was a consequence of the whole value delegate trick, but thankfully it still seems to work just fine in all other processors on UWP, and the issue was only when building for ARM32 anyway. It's great that the .NET Native team could identified exactly the faulting methods so we can just deoptimize them instead of burning performance for the whole library, yay! 🚀

@codecov
Copy link

codecov bot commented Oct 16, 2020

Codecov Report

Merging #1391 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1391   +/-   ##
=======================================
  Coverage   82.83%   82.84%           
=======================================
  Files         690      690           
  Lines       30843    30848    +5     
  Branches     3542     3542           
=======================================
+ Hits        25550    25555    +5     
  Misses       4572     4572           
  Partials      721      721           
Flag Coverage Δ
#unittests 82.84% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
...on/GlobalHistogramEqualizationProcessor{TPixel}.cs 96.42% <100.00%> (+0.35%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5bb01ac...ff89b74. Read the comment docs.

Copy link
Member

@Sergio0694 Sergio0694 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it! 🚀

{
ref int histogramBase = ref MemoryMarshal.GetReference(this.histogramBuffer.GetSpan());
ref TPixel pixelBase = ref MemoryMarshal.GetReference(this.source.GetPixelRowSpan(y));
int levels = this.luminanceLevels;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some bonus loop hoisting, nice 🚀

/// <inheritdoc/>
#if NETSTANDARD2_0
// https://github.com/SixLabors/ImageSharp/issues/1204
[MethodImpl(MethodImplOptions.NoOptimization)]
Copy link
Member

@Sergio0694 Sergio0694 Oct 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shame that we can't just target UWP specifically for this, but .NET Standard 2.0 as a whole should mostly be for back-compat anyway, so this seems absolutely fine to me. This whole processor is not one of the most used though, so this shouldn't affect most code paths and usages of the library anyway, which is great.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! Just typed the same thing below 😝

@JimBobSquarePants
Copy link
Member Author

@Sergio0694 Yeah, really glad to have made some progress here. Would have been nice to have been able to target a little more specifically but I don't believe it's possible (is it?)

@JimBobSquarePants JimBobSquarePants merged commit cd4f565 into master Oct 16, 2020
@JimBobSquarePants JimBobSquarePants deleted the js/fix-1204 branch October 16, 2020 21:41
@Sergio0694
Copy link
Member

@JimBobSquarePants It actually is, though it requires some more setup.
We'd need to build the library using MSBuild.Sdk.Extras and add uap10.0.17763 (or above) as one of the targets.
This way UWP devs would get the UWP class library directly. In theory this should also work if they're using ImageSharp from a .NET Standard 2.0 project and then referencing it from the UWP app, as NuGet should then resolve the most specific target at build time, which would be the UWP one. You can see an example of this here, we're using MSBuild.Sdk.Extras for the UWP packages in the toolkit as well.

This might not be worth it though considering that both UWP as a whole (I mean, .NET Native) and .NET Standard 2.0 are basically mostly considered legacy at this point, as people gradually just move to .NET 5. Given that the change is so small to fix this, it might be worth it to just keep the library as is. Thoughts?

@JimBobSquarePants
Copy link
Member Author

Sounds like a lot of extra work/testing for little reward. Let's stick to what we have for now.

@Sergio0694
Copy link
Member

The day UWP finally switches to .NET 6 I will pop the biggest bottle of champagne ever made 🤣

@JimBobSquarePants
Copy link
Member Author

I'll drink to that! 🍾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImageSharp-rc1 fails to build on UWP Release ARM

3 participants