dotnet/roslyn

Find and pass "op_Equality" MethodInfo to the expression tree factory for Equals.

Open

#11,336 opened on May 16, 2016

View on GitHub
 (1 comment) (0 reactions) (0 assignees)C# (20,414 stars) (4,257 forks)batch import
Area-CompilersBugLanguage-C#Language-VBTenet-Performancehelp wanted

Description

Not passing the method only results in forcing the "Equals" to search for the method using reflection when it is called. We would get the same expression tree, but will do more allocations.

"op_Equality" is a Special method and a part of public API of System.String Obtaining "op_Equality" at compile time is cheap and already done in all cases except when Expression Trees are involved. Note: We can rely on the operator always be there (it is likely an error if it is not in the first place), and if not, we can still pass "null", although that would be a nearly impossible case in reality which would likely fail at run time before producing any trees anyways.

The situation is worse on CoreFX because of additional allocation due to the use of more general (and more expensive) reflection APIs (see: https://github.com/dotnet/corefx/issues/8576 )

The issue was reported as causing excessive and unnecessary allocations in common patterns used by ASP.Net apps. A typical example is https://github.com/aspnet/MusicStore.

Contributor guide