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.

贡献者指南