dotnet/roslyn

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

Open

#11,336 建立於 2016年5月16日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)C# (4,257 fork)batch import
Area-CompilersBugLanguage-C#Language-VBTenet-Performancehelp wanted

倉庫指標

Star
 (20,414 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 256 個 PR)

描述

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.

貢獻者指南