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

Improved Guard APIs codegen #12

Merged
merged 7 commits into from
Nov 29, 2020
Merged

Conversation

Sergio0694
Copy link
Member

The JIT assumes that forward branches are always taken, and with the custom ThrowHelper methods used in the Guard APIs having the [MethodImpl] attributes, it couldn't see that they were always throwing, so the resulting codegen was not optimal. I've inverted all the conditions so that the forward branch is the likely one (the one that doesn't fault). This allowes the JIT to properly optimize the codegen in methods using the Guard APIs, eg. by only using jumps for the faulting paths and placing them further down in the code, with the likely branch not having to jump instead. These are the same changes done in the Microsoft.Toolkit.Diagnostics.Guard class, see CommunityToolkit/WindowsCommunityToolkit#3323.

NOTE: @JimBobSquarePants not sure how to generate that .tt.bak file, could you tell me what steps I should do here?

@JimBobSquarePants
Copy link
Member

not sure how to generate that .tt.bak file, could you tell me what steps I should do here?

Easy peasy... I simply renamed the .tt file after I'd generated the classes from it! 😄

@Sergio0694
Copy link
Member Author

Oh...
Not sure why, I saw that .bak extension and just assumed it must've had to do with some custom build script or something 🤣

Well that worked, PR should be good to go now, thanks! 🎉

@Sergio0694 Sergio0694 marked this pull request as ready for review August 31, 2020 10:54
@JimBobSquarePants
Copy link
Member

I'm gonna see if I can get CI up and running for this PR to improve test visibility.

@JimBobSquarePants
Copy link
Member

JimBobSquarePants commented Sep 1, 2020

@MarcoRossignoli I hate to do this but I can't figure out why the code coverage reports here are empty?

Would you be able to take a quick look when you are able, no rush! Thanks!

Scratch that, figured it out! Because we are including the shared project directly into the test project I had to configure the .runsettings file in the following manner.

<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
    <DataCollectionRunSettings>
        <DataCollectors>
            <DataCollector friendlyName="XPlat code coverage">
                <Configuration>
                    <Format>lcov</Format>
                    <ExcludeByFile>**/tests/**/*.cs, **/**/*.Program.cs</ExcludeByFile>
                    <IncludeTestAssembly>true</IncludeTestAssembly>
                </Configuration>
            </DataCollector>
        </DataCollectors>
    </DataCollectionRunSettings>
</RunSettings>

https://github.com/SixLabors/SharedInfrastructure/pull/12/files#diff-7134c7037c9f1d02b0e4ea0be9828609R1-R14

@codecov
Copy link

codecov bot commented Sep 1, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@b0d4cd9). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #12   +/-   ##
=========================================
  Coverage          ?   19.77%           
=========================================
  Files             ?        4           
  Lines             ?      359           
  Branches          ?       88           
=========================================
  Hits              ?       71           
  Misses            ?      288           
  Partials          ?        0           
Flag Coverage Δ
#unittests 19.77% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out 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 b0d4cd9...d7e37f1. Read the comment docs.

@JimBobSquarePants
Copy link
Member

@Sergio0694 Our code coverage is appalling. I'd like to do some work on that before merging.

@Sergio0694
Copy link
Member Author

@JimBobSquarePants Are we missing tests for ThrowHelper or for Guard too?
I could port/adapt some of those I have in the toolkit (see here)?

Also, side question - do we need another PR to update the submodule reference for ImageSharp after this is merged?
Not super familiar with submodules myself so not sure if there's some automation there or something 😅

@JimBobSquarePants
Copy link
Member

JimBobSquarePants commented Sep 2, 2020

@Sergio0694 Guard and DebugGuard should cover everything we need as they call ThrowHelper

You can see the coverage here.
https://codecov.io/gh/SixLabors/SharedInfrastructure/pull/12/tree

Once we've finished, yep it's a new PR for each consuming repo. Hopefully this is the last change we'll see for a while.

@MarcoRossignoli
Copy link

Hi guys!

Scratch that, figured it out! Because we are including the shared project directly into the test project I had to configure the .runsettings file in the following manner.

Yep test project is not included in coverage by default

Let me know if need further assistance

@JimBobSquarePants
Copy link
Member

@MarcoRossignoli Thanks mate! Once I'd remembered how my project worked it was dead easy. Love how simple the configuration options are!

@JimBobSquarePants JimBobSquarePants merged commit 2754ccc into master Nov 29, 2020
@JimBobSquarePants JimBobSquarePants deleted the sp/guard-codegen-improvement branch November 29, 2020 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants