Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.

Removed Method Group conversions, more additions to equality.#1030

Closed
Mrnikbobjeff wants to merge 2 commits intoxamarin:mainfrom
Mrnikbobjeff:feature/MethodGroupConversionsAndEnums
Closed

Removed Method Group conversions, more additions to equality.#1030
Mrnikbobjeff wants to merge 2 commits intoxamarin:mainfrom
Mrnikbobjeff:feature/MethodGroupConversionsAndEnums

Conversation

@Mrnikbobjeff
Copy link
Copy Markdown
Contributor

Description of Change

Removed most method group conversions to be able to cache the delegate as this is currently forbidden by the standard for method group conversions. Here is the enum case benchmark as linked in the first issue, here we see the effect of method group conversions.

API Changes

None

Behavioral Changes

They should simply see less allocations throughout the app.

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard
  • Updated documentation (see walkthrough)

@jamesmontemagno
Copy link
Copy Markdown
Collaborator

When it comes to this will have @terrajobst validate.

@terrajobst
Copy link
Copy Markdown

When it comes to this will have @terrajobst validate.

@jaredpar is more appropriate to validate this change

terrajobst
terrajobst previously approved these changes Dec 19, 2019
Copy link
Copy Markdown

@terrajobst terrajobst left a comment

Choose a reason for hiding this comment

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

Seems reasonable if true; @jaredpar would not know for sure.

@Mrnikbobjeff
Copy link
Copy Markdown
Contributor Author

Just for further reference, the current c# spec says the following about method group conversions in section 6.6 :"A new instance of the delegate type D is allocated. If there is not enough memory available to allocate the new instance, a System.OutOfMemoryException is thrown and no further steps are executed."
Concerning anonymous, the C# spec states the following in section 6.5.1: "Conversions of semantically identical anonymous functions with the same (possibly empty) set of captured outer variable instances to the same delegate types are permitted (but not required) to return the same delegate instance."
There was some work going on to allow method group conversions to be cached, but this does not appear to be on the roadmap to happen in the near future.

@mattleibow
Copy link
Copy Markdown
Member

Interesting... I always thought these anonymous delegates would be worse. Seems C# tries to catch me out even more ;)

@Mrnikbobjeff
Copy link
Copy Markdown
Contributor Author

@jaredpar Did you have a change to look over the changes yet?

@jaredpar
Copy link
Copy Markdown

@Mrnikbobjeff the method group conversions to delegates look good

@AmrAlSayed0
Copy link
Copy Markdown

dotnet/roslyn#5835 I think it is related to this issue, though this is the roslyn compiler, I don't know if the same issue is in the mono compiler.

@Mrnikbobjeff
Copy link
Copy Markdown
Contributor Author

That was the issue I referenced in the ticket. No matter what mono does, as long as it abides by the standard it will be exactly the same. Feel free to try yourself with the linked benchmark, you just have to add a ClrJob for mono

@mattleibow mattleibow changed the base branch from master to main June 9, 2020 13:48
@mattleibow mattleibow dismissed terrajobst’s stale review June 9, 2020 13:48

The base branch was changed.

@Mrnikbobjeff Mrnikbobjeff mentioned this pull request Oct 14, 2020
5 tasks
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.

6 participants