Skip to content

Conversation

@swoolcock
Copy link
Contributor

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

Adds some calls to Unsafe.SizeOf for various primitives and structs to prevent JIT errors on iOS.
Also seeds the decoders for a given pixel format, which should solve #776.
Note that although JPEG will now also load without crashing, it is incredibly slow on Xamarin.iOS. A 1366x768 JPEG takes about 5 seconds to load on an iPad Pro.

As per the previous PR #767, this is a difficult one to write tests for.

@CLAassistant
Copy link

CLAassistant commented Dec 8, 2018

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

I think we should hide InitializeUnsafe() from the outside, otherwise everything looks good.

{
decoder.Decode<TPixel>(Configuration.Default, null);
}
catch
Copy link
Member

Choose a reason for hiding this comment

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

This isn't nice, but can't think of a better solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I agree. Would be nice if there were a way to make a dummy call to Decode without generating exceptions.

/// <summary>
/// Seeds the <see cref="System.Runtime.CompilerServices.Unsafe"/> calls.
/// </summary>
public static void SeedUnsafe()
Copy link
Member

Choose a reason for hiding this comment

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

Looks like an implementation detail from the outside.

Can't we hide this from the outside invoking it internally in a lazy way when Seed<TPixel> (and other variants) are invoked?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll lazy call this (once) from Seed<TPixel> and push.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling it from the static constructor instead, since that's guaranteed to only execute once.

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

Yeah, better to use the static constructor in this case!

Looks like also seeding the encoder is an easy addition, but I may miss something here.

/// </summary>
/// <param name="decoder">The image decoder to seed..</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
private static void AotDecoder<TPixel>(IImageDecoder decoder)
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it worth to also seed both decoder and encoder instead?

private static void SeedCodecs<TPixel>(IImageDecoder decoder, IImageEncoder encoder)
{
   // invoke both decoder and encoder in separate try-catch blocks
}

@swoolcock
Copy link
Contributor Author

I'm not sure what the deal is with that CI error, I can't see how any of my changes could have triggered it.

@codecov
Copy link

codecov bot commented Dec 15, 2018

Codecov Report

Merging #785 into master will increase coverage by 0.01%.
The diff coverage is 90.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #785      +/-   ##
==========================================
+ Coverage    88.7%   88.71%   +0.01%     
==========================================
  Files        1012     1012              
  Lines       43248    43270      +22     
  Branches     3127     3127              
==========================================
+ Hits        38363    38388      +25     
- Misses       4181     4183       +2     
+ Partials      704      699       -5
Impacted Files Coverage Δ
src/ImageSharp/Advanced/AotCompilerTools.cs 95.34% <90.9%> (-4.66%) ⬇️
src/ImageSharp/Formats/Gif/GifDecoderCore.cs 79.91% <0%> (+0.42%) ⬆️
src/ImageSharp/Formats/Png/PngEncoderCore.cs 94.32% <0%> (+0.81%) ⬆️
src/ImageSharp/Advanced/AdvancedImageExtensions.cs 82.35% <0%> (+5.88%) ⬆️

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 590609a...50c3d7f. Read the comment docs.

@codecov
Copy link

codecov bot commented Dec 15, 2018

Codecov Report

Merging #785 into master will increase coverage by 0.04%.
The diff coverage is 90.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #785      +/-   ##
==========================================
+ Coverage   88.66%   88.71%   +0.04%     
==========================================
  Files        1012     1012              
  Lines       43222    43270      +48     
  Branches     3120     3127       +7     
==========================================
+ Hits        38324    38388      +64     
- Misses       4160     4183      +23     
+ Partials      738      699      -39
Impacted Files Coverage Δ
src/ImageSharp/Advanced/AotCompilerTools.cs 95.34% <90.9%> (-4.66%) ⬇️
...ng/Processors/Convolution/GaussianBlurProcessor.cs 73.33% <0%> (-19.26%) ⬇️
src/ImageSharp/Primitives/DenseMatrix{T}.cs 71.73% <0%> (-14.8%) ⬇️
...Processors/Convolution/GaussianSharpenProcessor.cs 79.31% <0%> (-14.63%) ⬇️
...cessing/Processors/Convolution/BoxBlurProcessor.cs 100% <0%> (ø) ⬆️
...ts/ImageSharp.Tests/Primitives/DenseMatrixTests.cs 100% <0%> (ø) ⬆️
...files/ICC/DataWriter/IccDataWriter.TagDataEntry.cs 77.14% <0%> (ø) ⬆️
src/ImageSharp/Processing/ResizeHelper.cs 42.42% <0%> (ø) ⬆️
...ils/ReferenceImplementations.StandardIntegerDCT.cs 93.68% <0%> (ø) ⬆️
...files/ICC/DataReader/IccDataReader.TagDataEntry.cs 85.91% <0%> (+0.28%) ⬆️
... and 20 more

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 cbfb8dc...24236c8. Read the comment docs.

@antonfirsov
Copy link
Member

It was a typical intermittent test failure, related to test-only code. Restarting the build helped.

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

@JimBobSquarePants anything against merging this now?

@JimBobSquarePants
Copy link
Member

JimBobSquarePants commented Dec 16, 2018

@antonfirsov Nope. I'll update from master and get it merged. @swoolcock Thanks for your help!

Note that although JPEG will now also load without crashing, it is incredibly slow on Xamarin.iOS. A 1366x768 JPEG takes about 5 seconds to load on an iPad Pro.

On that note, it's due to the current lack of SIMD support on those platforms - Our hands are tied by MS. There is improved support coming in NET Core 3.0 and future Mono though so fingers crossed we get what we need.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants