Skip to content
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

Improve CQ10 #783

Merged
merged 19 commits into from
Dec 12, 2018
Merged

Improve CQ10 #783

merged 19 commits into from
Dec 12, 2018

Conversation

iamcarbon
Copy link
Contributor

@iamcarbon iamcarbon commented Dec 5, 2018

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

  • Update BenchmarkDotNet and Moq Libs
  • Use unmanaged constraint on internal api
  • Remove redundant package references
  • Use new HashHelper overloads Use new HashCode.Combine polyfill
  • Cleanup the shared assembly properties (preferring auto generation)

@iamcarbon iamcarbon changed the title Cq10 Improve CQ10 Dec 5, 2018
@iamcarbon
Copy link
Contributor Author

Ready for review.

this.InputValues = inputValues;
this.ClutValues = clutValues;
this.OutputValues = outputValues;
this.InputValues = inputValues ?? throw new ArgumentNullException(nameof(inputValues));
Copy link
Member

Choose a reason for hiding this comment

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

I really prefer using Guard instead of the null-coalescing operator.

Copy link
Contributor Author

@iamcarbon iamcarbon Dec 6, 2018

Choose a reason for hiding this comment

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

They look nicer, but are they worth the expense of an extra call and a convoluted stack that shows that the exception occurred within the Guard method instead of the actual callsite? I would advocate that we eventually replace all Guard methods with methods that throw inline so the user knows exactly where the problem is.

return hashCode;
}
return HashHelpers.Combine(
(int)this.CurveType,
Copy link
Member

Choose a reason for hiding this comment

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

CurveType.GetHashCode()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
return HashHelpers.Combine(
base.GetHashCode(),
(int)this.ColorantType,
Copy link
Member

Choose a reason for hiding this comment

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

this.ColorantType.GetHashCode()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

hashCode = (hashCode * 397) ^ (this.InputValues?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.ClutValues?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.OutputValues?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ this.InputValues.GetHashCode();
Copy link
Member

Choose a reason for hiding this comment

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

Why are we not using HashHelpers.Combine here?

}
return HashHelpers.Combine(
base.GetHashCode(),
this.InputChannelCount,
Copy link
Member

Choose a reason for hiding this comment

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

this.InputChannelCount.GetHashCode()?

Copy link
Contributor Author

@iamcarbon iamcarbon Dec 6, 2018

Choose a reason for hiding this comment

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

Was on the fence whether or not to update all of these to use an integer or call GetHashCode and left as is for the PR.

base.GetHashCode(),
this.IlluminantXyz.GetHashCode(),
this.SurroundXyz.GetHashCode(),
(int)this.Illuminant);
Copy link
Member

Choose a reason for hiding this comment

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

this.Illuminant.GetHashCode()?

This is happening in other places also, now starting to wonder if you should not use GetHashCode for an int?

Copy link
Contributor Author

@iamcarbon iamcarbon Dec 6, 2018

Choose a reason for hiding this comment

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

Going to update these all to using GetHashCode() for consistency with the rest of the codebase.

@codecov
Copy link

codecov bot commented Dec 6, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@dce781d). Click here to learn what that means.
The diff coverage is 48.61%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #783   +/-   ##
=========================================
  Coverage          ?   88.68%           
=========================================
  Files             ?     1012           
  Lines             ?    43253           
  Branches          ?     3144           
=========================================
  Hits              ?    38359           
  Misses            ?     4192           
  Partials          ?      702
Impacted Files Coverage Δ
.../ImageSharp/Common/ParallelUtils/ParallelHelper.cs 100% <ø> (ø)
...MetaData/Profiles/ICC/Various/IccResponseNumber.cs 57.14% <0%> (ø)
...es/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs 50% <0%> (ø)
...les/ICC/TagDataEntries/IccSignatureTagDataEntry.cs 50% <0%> (ø)
.../Implementation/WorkingSpaces/GammaWorkingSpace.cs 35.71% <0%> (ø)
...Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs 50% <0%> (ø)
...ntries/IccProfileSequenceIdentifierTagDataEntry.cs 50% <0%> (ø)
...s/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs 50% <0%> (ø)
...mageSharp/MetaData/Profiles/ICC/Various/IccClut.cs 42.66% <0%> (ø)
...Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs 45.45% <0%> (ø)
... and 53 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 dce781d...31c2d4a. Read the comment docs.

@codecov
Copy link

codecov bot commented Dec 6, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@9446900). Click here to learn what that means.
The diff coverage is 23.39%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master    #783   +/-   ##
========================================
  Coverage          ?   88.7%           
========================================
  Files             ?    1012           
  Lines             ?   43248           
  Branches          ?    3127           
========================================
  Hits              ?   38363           
  Misses            ?    4181           
  Partials          ?     704
Impacted Files Coverage Δ
.../ImageSharp/Common/ParallelUtils/ParallelHelper.cs 100% <ø> (ø)
...mageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs 46.66% <0%> (ø)
...lementation/RGBPrimariesChromaticityCoordinates.cs 58.33% <0%> (ø)
...les/ICC/TagDataEntries/IccSignatureTagDataEntry.cs 50% <0%> (ø)
.../Implementation/WorkingSpaces/GammaWorkingSpace.cs 29.41% <0%> (ø)
...ntries/IccProfileSequenceIdentifierTagDataEntry.cs 50% <0%> (ø)
...mageSharp/MetaData/Profiles/ICC/Various/IccClut.cs 42.66% <0%> (ø)
...Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs 45.45% <0%> (ø)
...s/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs 50% <0%> (ø)
...DataEntries/IccMultiProcessElementsTagDataEntry.cs 60% <0%> (ø)
... and 68 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 9446900...4568a4b. Read the comment docs.

@iamcarbon
Copy link
Contributor Author

@dlemstra Thanks for the feedback. Addressed the PR with one comment. Let me know your thoughts on throws. I've been letting them slowly creep in in my prior PR's -- we should make a call.

@iamcarbon
Copy link
Contributor Author

@JimBobSquarePants PING.

@JimBobSquarePants
Copy link
Member

@iamcarbon Just landed back in Oz. Will review properly when over my jet lag.

Two things I’d like to see/discuss though.

  1. Potential use of Type forwarded HashCode from CoreFx. The API for that is lush.
  2. What does a stack trace for Guard vs non Guard look like?

@iamcarbon
Copy link
Contributor Author

@JimBobSquarePants I submitted a PR in core to polyfill HashCode. Stacktraces coming soon.

@JimBobSquarePants
Copy link
Member

Legend!

@iamcarbon
Copy link
Contributor Author

iamcarbon commented Dec 8, 2018

Here are examples of the stack traces.

For trivial argument validation on public methods, I believe we should prefer inline throws to improve the stack traces (brevity + clarity). This also eliminates code generation for the generic function and a call.

THROWING USING GUARD HELPER

E:\ImageSharp\src\ImageSharp\Common\Helpers\Guard.cs(294,0): at SixLabors.ImageSharp.Guard.ThrowArgumentNullException(String parameterName)
E:\ImageSharp\src\ImageSharp\Common\Helpers\Guard.cs(29,0): at SixLabors.ImageSharp.Guard.NotNull[T](T value, String parameterName)
E:\ImageSharp\src\ImageSharp\Formats\ImageFormatManager.cs(127,0): at SixLabors.ImageSharp.Formats.ImageFormatManager.SetEncoder(IImageFormat imageFormat, IImageEncoder encoder)
E:\ImageSharp\tests\ImageSharp.Tests\Formats\ImageFormatManagerTests.cs(34,0): at SixLabors.ImageSharp.Tests.ImageFormatManagerTests.Stack()

screen shot 2018-12-08 at 2 32 28 pm

THROWING DIRECTLY

E:\ImageSharp\src\ImageSharp\Formats\ImageFormatManager.cs(129,0): at SixLabors.ImageSharp.Formats.ImageFormatManager.SetEncoder(IImageFormat imageFormat, IImageEncoder encoder)
E:\ImageSharp\tests\ImageSharp.Tests\Formats\ImageFormatManagerTests.cs(34,0): at SixLabors.ImageSharp.Tests.ImageFormatManagerTests.Stack()

screen shot 2018-12-08 at 2 35 11 pm

@iamcarbon
Copy link
Contributor Author

Updated to use HashCode.Combine

@@ -18,19 +18,13 @@
<ProjectReference Include="..\..\src\ImageSharp\ImageSharp.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BitMiracle.LibJpeg.NET" Version="1.4.280" />
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="7.9.0.1" />
<PackageReference Include="xunit" Version="2.3.1" />
Copy link
Member

Choose a reason for hiding this comment

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

Are you able to shed any light into what issues are blocking us upgrading xunit?

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 spent 30 minutes on this before. I'll take another stab in CQ11.

Copy link
Member

Choose a reason for hiding this comment

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

Good man! 👍

@iamcarbon
Copy link
Contributor Author

@JimBobSquarePants -- what other rad .NETCORE stuff can we polyfill. :)

@JimBobSquarePants
Copy link
Member

Pulling this in now. Thanks again!!

@JimBobSquarePants JimBobSquarePants merged commit 590609a into SixLabors:master Dec 12, 2018
@iamcarbon iamcarbon deleted the cq10 branch December 13, 2018 16:19
antonfirsov pushed a commit to antonfirsov/ImageSharp that referenced this pull request Nov 11, 2019
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.

3 participants