-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expression compilation is slower in Net7. #76058
Comments
Tagging subscribers to this area: @cston Issue DetailsDescriptionOur app needs to compile more than 50000 expressions and the start. We noticed that the app starts slower when running under Net7 for more than 20 seconds. Configuration<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>Latest</LangVersion>
<Nullable>enable</Nullable>
<TieredCompilation>false</TieredCompilation>
<TieredCompilationQuickJit>false</TieredCompilationQuickJit>
<TieredCompilationQuickJitForLoops>false</TieredCompilationQuickJitForLoops>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
</ItemGroup>
</Project> using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using System.Linq.Expressions;
using System.Reflection;
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).RunAll();
[SimpleJob(RuntimeMoniker.Net50)]
[SimpleJob(RuntimeMoniker.Net60)]
[SimpleJob(RuntimeMoniker.Net70)]
public class Fixture
{
private PropertyInfo _propertyInfo;
public delegate object GetterFunc(object instance);
public Fixture()
{
_propertyInfo = typeof(Subject).GetProperty(nameof(Subject.MyProperty))!;
}
[Benchmark]
public GetterFunc Getter()
{
ParameterExpression instance = Expression.Parameter(typeof(Object), "instance");
UnaryExpression castedInstance = Expression.ConvertChecked(instance, _propertyInfo.DeclaringType!);
MemberExpression property = Expression.Property(castedInstance, _propertyInfo);
UnaryExpression convert = Expression.Convert(property, typeof(object));
LambdaExpression expression = Expression.Lambda<GetterFunc>(convert, instance);
return (GetterFunc)expression.Compile();
}
}
public class Subject
{
public string MyProperty
{
get;
set;
}
} Regression?Looks so. Net6 compiles expression faster. Data
|
Related to #75891? Can you try this on the latest .NET 7 builds in dotnet/installer: https://github.com/dotnet/installer/tree/release/7.0.1xx |
@reflectronic sorry, I'm not so qualified to build dotnet tools from scratch. |
@reflectronic I found the link in the table)) Looks like it's fixed:
(note, net6 is faster a bit yet) Thank you! |
This is a performance vs security tradeoff, and we're defaulting to a more secure implementation at the expense of a small perf impact (which we can also work to decrease further in time). |
.... are source generators an option for you? That is, do you actually need the runtime generation, or is it just attempting to generate something that would otherwise require lots of manual code writing. |
@Clockwork-Muse yeah, SG is an option, but expensive option))
yep)) |
Description
Our app needs to compile more than 50000 expressions and the start. We noticed that the app starts slower when running under Net7 for more than 20 seconds.
Configuration
Regression?
Looks so. Net6 compiles expression faster.
Data
The text was updated successfully, but these errors were encountered: