Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Updated formatted GetResourceString code reduction#7136

Merged
jkotas merged 2 commits into
dotnet:masterfrom
benaadams:enviro
Sep 12, 2016
Merged

Updated formatted GetResourceString code reduction#7136
jkotas merged 2 commits into
dotnet:masterfrom
benaadams:enviro

Conversation

@benaadams
Copy link
Copy Markdown
Member

@benaadams benaadams commented Sep 11, 2016

Update to: "Reduce code bloat around formatted GetResourceString calls" #7007

Addresses the issues raised in #7007 (comment)

Jit-Diff

Summary:
(Note: Lower is better)

Total bytes of diff: -17495 (-0.54 % of base)
    diff is an improvement.

Total byte diff includes 325 bytes from reconciling methods
        Base had    0 unique methods,        0 unique bytes
        Diff had    3 unique methods,      325 unique bytes

Top file improvements by size (bytes):
      -17495 : System.Private.CoreLib.dasm (-0.54 % of base)

1 total files with size differences.

Top method regessions by size (bytes):
         128 : System.Private.CoreLib.dasm - Environment:GetResourceString(ref,ref,ref,ref,ref):ref
         110 : System.Private.CoreLib.dasm - Environment:GetResourceString(ref,ref,ref,ref):ref
          91 : System.Private.CoreLib.dasm - Environment:GetResourceString(ref,ref):ref
          87 : System.Private.CoreLib.dasm - Environment:GetResourceString(ref,ref,ref):ref
          45 : System.Private.CoreLib.dasm - CustomAttributeTypedArgument:EncodedValueToRawValue(long,int):ref

Top method improvements by size (bytes):
        -845 : System.Private.CoreLib.dasm - CLRIPropertyValueImpl:CoerceArrayValue(int):ref:this
        -440 : System.Private.CoreLib.dasm - CLRIPropertyValueImpl:CoerceScalarValue(int,ref):int
        -426 : System.Private.CoreLib.dasm - CLRIPropertyValueImpl:CoerceScalarValue(int,ref):long
        -235 : System.Private.CoreLib.dasm - __Error:WinIOError(int,ref)
        -213 : System.Private.CoreLib.dasm - CLRIPropertyValueImpl:CoerceScalarValue(int,ref):ubyte

371 total methods with size differences.

/cc @jamesqo

@benaadams
Copy link
Copy Markdown
Member Author

benaadams commented Sep 11, 2016

@jamesqo not sure if updating your PR breaks OSS protocol?

@khellang
Copy link
Copy Markdown
Member

khellang commented Sep 11, 2016

I'd probably do it the other way around though. Send a PR to @jamesqo's fork, targeting the less-resource-bloat branch and have it automatically included in #7007 when merged 😄

@benaadams
Copy link
Copy Markdown
Member Author

Good idea

@jamesqo
Copy link
Copy Markdown

jamesqo commented Sep 11, 2016

Hah, no, it's fine. I've closed my PR. I wasn't working on it since I'm planning to introduce a new attribute specifically to denote methods that use StackCrawlMark, so then NoInlining methods that do not use those types of variables will not be pessimized. But in the meantime, this is probably OK to go ahead with.

@benaadams
Copy link
Copy Markdown
Member Author

Can't do that, branch has been deleted 😢

@benaadams
Copy link
Copy Markdown
Member Author

Ah ok 😄

/cc @jkotas

Comment thread src/mscorlib/src/System/Environment.cs Outdated

// NoInlining causes the caller and callee to not be inlined in mscorlib as it is an assumption of StackCrawlMark use
[MethodImpl(MethodImplOptions.NoInlining)]
private static String GetResourceString(string key, params object[] values)
Copy link
Copy Markdown

@jamesqo jamesqo Sep 11, 2016

Choose a reason for hiding this comment

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

This should be kept internal, otherwise things like

Environment.GetResourceString("Foo", new object[] { ... });

will break since they now call the (string, object) overload.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, ok, then have to move the no-inlining about

@benaadams
Copy link
Copy Markdown
Member Author

Re-analysing with code adjustment

Comment thread src/mscorlib/src/System/Environment.cs Outdated
// NoInlining causes the caller and callee to not be inlined in mscorlib as it is an assumption of StackCrawlMark use
[MethodImpl(MethodImplOptions.NoInlining)]
private static String GetResourceString(string key, params object[] values)
private static String GetResourceString(object[] values, string key)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Instead of shifting around all of the parameters which will make this confusing for readers + generates a larger git diff, you could just call this GetResourceStringCore or GetResourceStringInternal?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Shouldn't change the git diff? Anyway less confusion makes sense, made the change

@benaadams
Copy link
Copy Markdown
Member Author

Still good

Summary:
(Note: Lower is better)

Total bytes of diff: -17495 (-0.54 % of base)
    diff is an improvement.

Total byte diff includes 325 bytes from reconciling methods
        Base had    0 unique methods,        0 unique bytes
        Diff had    3 unique methods,      325 unique bytes

Top file improvements by size (bytes):
      -17495 : System.Private.CoreLib.dasm (-0.54 % of base)

1 total files with size differences.

Top method regessions by size (bytes):
         128 : System.Private.CoreLib.dasm - Environment:GetResourceString(ref,ref,ref,ref,ref):ref
         110 : System.Private.CoreLib.dasm - Environment:GetResourceString(ref,ref,ref,ref):ref
          91 : System.Private.CoreLib.dasm - Environment:GetResourceString(ref,ref):ref
          87 : System.Private.CoreLib.dasm - Environment:GetResourceString(ref,ref,ref):ref
          45 : System.Private.CoreLib.dasm - CustomAttributeTypedArgument:EncodedValueToRawValue(long,int):ref

Top method improvements by size (bytes):
        -845 : System.Private.CoreLib.dasm - CLRIPropertyValueImpl:CoerceArrayValue(int):ref:this
        -440 : System.Private.CoreLib.dasm - CLRIPropertyValueImpl:CoerceScalarValue(int,ref):int
        -426 : System.Private.CoreLib.dasm - CLRIPropertyValueImpl:CoerceScalarValue(int,ref):long
        -235 : System.Private.CoreLib.dasm - __Error:WinIOError(int,ref)
        -213 : System.Private.CoreLib.dasm - CLRIPropertyValueImpl:CoerceScalarValue(int,ref):ubyte

371 total methods with size differences.

Comment thread src/mscorlib/src/System/Environment.cs Outdated
return GetResourceStringFormatted(key, new object[] { val0, val1, val2, val3, val4, val5 });
}

internal static String GetResourceStrings(string key, params object[] values)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

GetResourceString

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sigh... was so it didn't get caught in my renaming,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed, good spot.

@benaadams
Copy link
Copy Markdown
Member Author

Need to add [System.Security.SecuritySafeCritical] to all the methods?

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Sep 12, 2016

Need to add [System.Security.SecuritySafeCritical] to all the methods?

It should not be needed.

@benaadams
Copy link
Copy Markdown
Member Author

@dotnet-bot test Linux ARM Emulator Cross Debug Build

@jkotas jkotas merged commit 762833d into dotnet:master Sep 12, 2016
@jkotas
Copy link
Copy Markdown
Member

jkotas commented Sep 12, 2016

Thank you!

@benaadams benaadams deleted the enviro branch October 13, 2016 08:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants