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

Address PR feedback for change adding key to KeyNotFoundException#15234

Merged
jkotas merged 6 commits into
dotnet:masterfrom
Anipik:KeyException
Dec 6, 2017
Merged

Address PR feedback for change adding key to KeyNotFoundException#15234
jkotas merged 6 commits into
dotnet:masterfrom
Anipik:KeyException

Conversation

@Anipik
Copy link
Copy Markdown

@Anipik Anipik commented Nov 27, 2017

issue- dotnet/corefx#5188
corefx pr - dotnet/corefx#25472
Related Coreclr Pr - #15201

@Anipik Anipik requested a review from danmoseley November 27, 2017 19:56
@jkotas
Copy link
Copy Markdown
Member

jkotas commented Nov 28, 2017

@Anipik Could you please write better commit description than just Changes?

https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/contributing.md#commit-messages has some tips on how to write good commit messages.

Comment thread src/mscorlib/src/System/ThrowHelper.cs Outdated
internal static void ThrowKeyNotFoundException(object key)
{
throw new KeyNotFoundException(key.ToString());
throw new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please change this to:

internal static void ThrowKeyNotFoundException(object key)
{
    throw GetKeyNotFoundException(object key);
}

to be consistent with the other similar methods? It will let the JIT to generate better code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@jkotas I understand why the ThrowXX method is valuable - the comment explains. Why is it found helpful to further break out constructing the exception?

Copy link
Copy Markdown
Member

@jkotas jkotas Nov 29, 2017

Choose a reason for hiding this comment

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

JIT will look into small methods to observe what they do. If the method always throws exception, the JIT will move the call to it to the "cold" section of the code and it will also know that the method will never return.

Breaking out constructing of the exception allows this optimization to kick in. The exception construction is large enough piece of code to prevents the optimization from kicking in.

Check the discussion in #7580 that introduced this optimization.

Comment thread src/mscorlib/src/System/ThrowHelper.cs Outdated
internal static void ThrowKeyNotFoundException(object key)
{
throw new KeyNotFoundException(key.ToString());
throw GetKeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You are doing this twice now. It should be done inside the Get... method only.

@danmoseley danmoseley changed the title KeyNotFoundException Address PR feedback for change adding key to KeyNotFoundException Nov 29, 2017
@danmoseley
Copy link
Copy Markdown
Member

@Anipik I improved the title.

@Anipik
Copy link
Copy Markdown
Author

Anipik commented Dec 5, 2017

@jkotas is this Pr ready to merge ?

Copy link
Copy Markdown
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks!

@jkotas jkotas merged commit 2005790 into dotnet:master Dec 6, 2017
jashook pushed a commit to jashook/coreclr that referenced this pull request Dec 12, 2017
…tnet#15234)

* Throwing KeyNotFoundException using Throw + get for JIT to generate better code for ii
@Anipik Anipik deleted the KeyException branch December 13, 2017 22:25
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.

3 participants