Open sebastienros opened 1 year ago
My initial thinking is that this is caused by defaulting TrimMode=partial
in ASP.NET's Web Sdk. See https://github.com/dotnet/sdk/issues/30059.
When I run the publish as above, it takes 7:43
on my machine. Of that, 7:26
is spent in the IlcCompile
Exec.
When I run the publish with -p:TrimMode=full
, it takes 3:10
. So over half of the time is taken off, because it is generating code for all methods in used assemblies.
Even with "full" trimming enabled, the resulting app is 72 MB on Windows.
You can see all of the assemblies being referenced by looking in obj\Release\net8.0\win-x64\native\Benchmarks.ilc.rsp
. I've dumped them here for convenience:
Looking at the mstat file for the TrimMode=full
case, here are the largest assemblies by method size:
// ********** Methods Total Size 37,584,176
System.Private.CoreLib 9,102,316
Npgsql 4,659,133
System.Private.Xml 2,758,801
System.Linq 2,148,272
System.Text.Json 2,099,626
System.Private.CompilerGenerated 1,869,831
Microsoft.EntityFrameworkCore 1,389,980
Microsoft.Data.SqlClient 910,465
Microsoft.EntityFrameworkCore.Relational 876,296
System.Data.Common 795,546
Microsoft.Identity.Client 674,231
Microsoft.AspNetCore.Server.Kestrel.Core 587,972
System.Private.DataContractSerialization 539,389
System.Net.Http 534,949
Microsoft.AspNetCore.Mvc.Core 468,516
System.Collections.Concurrent 450,727
System.Security.Cryptography 446,655
Microsoft.IdentityModel.Tokens 407,049
System.Linq.Expressions 389,653
Newtonsoft.Json 346,939
Microsoft.CSharp 332,321
Microsoft.Extensions.Logging.Console 324,343
System.Text.RegularExpressions 291,218
By Namespace:
// ********** Size By Namespace
System.Collections.Generic 6,599,056
System.Runtime.CompilerServices 5,042,557
System 4,685,769
Npgsql.Internal.TypeHandlers 3,619,366
System.Linq 3,219,973
Internal.CompilerGenerated 1,718,328
Npgsql.Internal.TypeHandling 1,419,909
System.Text.Json.Serialization.Converters 1,197,906
System.Xml 1,148,438
System.Threading.Tasks 761,097
System.Xml.Schema 680,452
Microsoft.Data.SqlClient 649,593
System.Collections.Concurrent 643,296
System.Text.Json.Serialization.Metadata 639,582
System.Xml.Serialization 585,475
System.Data 577,972
System.Linq.Expressions 505,125
Npgsql 449,200
System.Net.Http 433,449
System.Text.Json.Serialization 411,273
Microsoft.EntityFrameworkCore.Metadata.Internal 379,700
Microsoft.Extensions.Logging.Console 324,844
System.Text.Json 310,122
And the "blobs" size:
// ********** Blobs Total Size 26,628,100
Metadata 3,912,870
ArrayOfFrozenObjects 2,390,496
TypeGenericDictionary 2,243,696
ResourceData 2,102,349
MethodGenericDictionary 1,887,688
GenericMethodsHashtable 1,645,579
ExternalReferencesTable 1,414,300
StackTraceMethodMapping 1,244,808
InterfaceDispatchCellSection 1,045,104
WritableData 980,416
NativeLayoutInfo 960,329
FatFunctionPointer 844,192
ReflectionInvokeMap 792,698
GenericComposition 729,764
GenericTypesHashtable 694,361
InterfaceDispatchMap 442,722
EETypeOptionalFields 300,073
MethodReadOnlyData 280,636
StaticsInfoHashtable 278,641
NonGCStatics 263,255
FieldRvaData 227,118
SealedVTable 213,320
ReadyToRunHelper 187,173
GCStatics 186,896
TypeMetadataMap 174,902
ArrayOfEmbeddedPointers 143,688
GCStaticsPreInitData 134,776
ReflectionVirtualInvokeMap 130,708
ExactMethodInstantiations 103,842
There's just a LOT of code to go through here.
cc @MichalStrehovsky
Does the publish print any messages about generic recursion (not warnings, just messages)? Last time I checked npgsql had a generic recursion and we spent most of the time/size expanding it and then trying to not run out of memory/compile forever.
Does the publish print any messages about generic recursion (not warnings, just messages)?
Not that I can see. Just running ilc @...rsp
directly in my terminal, I don't see any messages beyond the warnings:
C:\Users\eerhardt\.nuget\packages\npgsql\6.0.0\lib\net6.0\Npgsql.dll: warning IL2104: Assembly 'Npgsql' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\git\benchmarks\src\Benchmarks\Startup.cs(55): Trim analysis warning IL2026: Benchmarks.Startup.ConfigureServices(IServiceCollection): Using member 'Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure<AppSettings>(IServiceCollection,IConfiguration)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved.
C:\git\benchmarks\src\Benchmarks\Startup.cs(55): AOT analysis warning IL3050: Benchmarks.Startup.ConfigureServices(IServiceCollection): Using member 'Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure<AppSettings>(IServiceCollection,IConfiguration)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Binding strongly typed objects to configuration values may require generating dynamic code at runtime.
C:\git\benchmarks\src\Benchmarks\Startup.cs(64): Trim analysis warning IL2026: Benchmarks.Startup.ConfigureServices(IServiceCollection): Using member 'Microsoft.Extensions.Configuration.ConfigurationBinder.Get<AppSettings>(IConfiguration)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.
C:\git\benchmarks\src\Benchmarks\Startup.cs(64): AOT analysis warning IL3050: Benchmarks.Startup.ConfigureServices(IServiceCollection): Using member 'Microsoft.Extensions.Configuration.ConfigurationBinder.Get<AppSettings>(IConfiguration)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Binding strongly typed objects to configuration values requires generating dynamic code at runtime, for example instantiating generic types.
C:\Users\eerhardt\.nuget\packages\microsoft.aspnetcore.app.runtime.win-x64\8.0.0-alpha.1.23058.7\runtimes\win-x64\lib\net8.0\Microsoft.AspNetCore.Hosting.dll: warning IL3053: Assembly 'Microsoft.AspNetCore.Hosting' produced AOT analysis warnings.
C:\git\benchmarks\src\Benchmarks\Middleware\JsonMiddleware.cs(56): Trim analysis warning IL2026: Benchmarks.Middleware.JsonMiddleware.Invoke(HttpContext): Using member 'System.Text.Json.JsonSerializer.SerializeAsync<JsonMessage>(Stream,JsonMessage,JsonSerializerOptions,CancellationToken)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
C:\git\benchmarks\src\Benchmarks\Middleware\JsonMiddleware.cs(56): AOT analysis warning IL3050: Benchmarks.Middleware.JsonMiddleware.Invoke(HttpContext): Using member 'System.Text.Json.JsonSerializer.SerializeAsync<JsonMessage>(Stream,JsonMessage,JsonSerializerOptions,CancellationToken)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
ILC: Trim analysis warning IL2026: Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Singleton<IConfigureOptions`1<JsonConsoleFormatterOptions>,ConsoleLoggerFormatterConfigureOptions`2<JsonConsoleFormatter,JsonConsoleFormatterOptions>>(): Using member 'Microsoft.Extensions.Logging.ConsoleLoggerFormatterConfigureOptions`2<JsonConsoleFormatter,JsonConsoleFormatterOptions>.ConsoleLoggerFormatterConfigureOptions`2(ILoggerProviderConfiguration`1<ConsoleLoggerProvider>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved.
ILC: Trim analysis warning IL2026: Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Describe<IConfigureOptions`1<JsonConsoleFormatterOptions>,ConsoleLoggerFormatterConfigureOptions`2<JsonConsoleFormatter,JsonConsoleFormatterOptions>>(ServiceLifetime): Using member 'Microsoft.Extensions.Logging.ConsoleLoggerFormatterConfigureOptions`2<JsonConsoleFormatter,JsonConsoleFormatterOptions>.ConsoleLoggerFormatterConfigureOptions`2(ILoggerProviderConfiguration`1<ConsoleLoggerProvider>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved.
ILC: Trim analysis warning IL2026: Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Singleton<IConfigureOptions`1<ConsoleFormatterOptions>,ConsoleLoggerFormatterConfigureOptions`2<SystemdConsoleFormatter,ConsoleFormatterOptions>>(): Using member 'Microsoft.Extensions.Logging.ConsoleLoggerFormatterConfigureOptions`2<SystemdConsoleFormatter,ConsoleFormatterOptions>.ConsoleLoggerFormatterConfigureOptions`2(ILoggerProviderConfiguration`1<ConsoleLoggerProvider>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved.
ILC: Trim analysis warning IL2026: Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Describe<IConfigureOptions`1<ConsoleFormatterOptions>,ConsoleLoggerFormatterConfigureOptions`2<SystemdConsoleFormatter,ConsoleFormatterOptions>>(ServiceLifetime): Using member 'Microsoft.Extensions.Logging.ConsoleLoggerFormatterConfigureOptions`2<SystemdConsoleFormatter,ConsoleFormatterOptions>.ConsoleLoggerFormatterConfigureOptions`2(ILoggerProviderConfiguration`1<ConsoleLoggerProvider>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved.
ILC: Trim analysis warning IL2026: Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Singleton<IConfigureOptions`1<SimpleConsoleFormatterOptions>,ConsoleLoggerFormatterConfigureOptions`2<SimpleConsoleFormatter,SimpleConsoleFormatterOptions>>(): Using member 'Microsoft.Extensions.Logging.ConsoleLoggerFormatterConfigureOptions`2<SimpleConsoleFormatter,SimpleConsoleFormatterOptions>.ConsoleLoggerFormatterConfigureOptions`2(ILoggerProviderConfiguration`1<ConsoleLoggerProvider>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved.
ILC: Trim analysis warning IL2026: Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Describe<IConfigureOptions`1<SimpleConsoleFormatterOptions>,ConsoleLoggerFormatterConfigureOptions`2<SimpleConsoleFormatter,SimpleConsoleFormatterOptions>>(ServiceLifetime): Using member 'Microsoft.Extensions.Logging.ConsoleLoggerFormatterConfigureOptions`2<SimpleConsoleFormatter,SimpleConsoleFormatterOptions>.ConsoleLoggerFormatterConfigureOptions`2(ILoggerProviderConfiguration`1<ConsoleLoggerProvider>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved.
ILC: Trim analysis warning IL2026: Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Singleton<IConfigureOptions`1<ConsoleLoggerOptions>,LoggerProviderConfigureOptions`2<ConsoleLoggerOptions,ConsoleLoggerProvider>>(): Using member 'Microsoft.Extensions.Logging.Configuration.LoggerProviderConfigureOptions`2<ConsoleLoggerOptions,ConsoleLoggerProvider>.LoggerProviderConfigureOptions`2(ILoggerProviderConfiguration`1<ConsoleLoggerProvider>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved.
ILC: Trim analysis warning IL2026: Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Describe<IConfigureOptions`1<ConsoleLoggerOptions>,LoggerProviderConfigureOptions`2<ConsoleLoggerOptions,ConsoleLoggerProvider>>(ServiceLifetime): Using member 'Microsoft.Extensions.Logging.Configuration.LoggerProviderConfigureOptions`2<ConsoleLoggerOptions,ConsoleLoggerProvider>.LoggerProviderConfigureOptions`2(ILoggerProviderConfiguration`1<ConsoleLoggerProvider>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved.
C:\Users\eerhardt\.nuget\packages\microsoft.data.sqlite.core\6.0.0\lib\net6.0\Microsoft.Data.Sqlite.dll: warning IL2104: Assembly 'Microsoft.Data.Sqlite' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\microsoft.entityframeworkcore\6.0.0\lib\net6.0\Microsoft.EntityFrameworkCore.dll: warning IL2104: Assembly 'Microsoft.EntityFrameworkCore' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\microsoft.aspnetcore.app.runtime.win-x64\8.0.0-alpha.1.23058.7\runtimes\win-x64\lib\net8.0\Microsoft.AspNetCore.Mvc.Core.dll: warning IL2104: Assembly 'Microsoft.AspNetCore.Mvc.Core' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\microsoft.data.sqlclient\4.0.0\runtimes\win\lib\netcoreapp3.1\Microsoft.Data.SqlClient.dll: warning IL2104: Assembly 'Microsoft.Data.SqlClient' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\microsoft.entityframeworkcore\6.0.0\lib\net6.0\Microsoft.EntityFrameworkCore.dll: warning IL3053: Assembly 'Microsoft.EntityFrameworkCore' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\microsoft.aspnetcore.app.runtime.win-x64\8.0.0-alpha.1.23058.7\runtimes\win-x64\lib\net8.0\Microsoft.AspNetCore.Mvc.Core.dll: warning IL3053: Assembly 'Microsoft.AspNetCore.Mvc.Core' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\newtonsoft.json\12.0.2\lib\netstandard2.0\Newtonsoft.Json.dll: warning IL2104: Assembly 'Newtonsoft.Json' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\newtonsoft.json\12.0.2\lib\netstandard2.0\Newtonsoft.Json.dll: warning IL3053: Assembly 'Newtonsoft.Json' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\8.0.0-alpha.1.23058.2\framework\System.Linq.Expressions.dll: warning IL3053: Assembly 'System.Linq.Expressions' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\microsoft.entityframeworkcore.relational\6.0.0\lib\net6.0\Microsoft.EntityFrameworkCore.Relational.dll: warning IL2104: Assembly 'Microsoft.EntityFrameworkCore.Relational' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\microsoft.aspnetcore.app.runtime.win-x64\8.0.0-alpha.1.23058.7\runtimes\win-x64\lib\net8.0\Microsoft.AspNetCore.Mvc.ViewFeatures.dll: warning IL2104: Assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\microsoft.aspnetcore.app.runtime.win-x64\8.0.0-alpha.1.23058.7\runtimes\win-x64\lib\net8.0\Microsoft.AspNetCore.Mvc.Abstractions.dll: warning IL2104: Assembly 'Microsoft.AspNetCore.Mvc.Abstractions' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\microsoft.aspnetcore.app.runtime.win-x64\8.0.0-alpha.1.23058.7\runtimes\win-x64\lib\net8.0\Microsoft.AspNetCore.Mvc.Abstractions.dll: warning IL3053: Assembly 'Microsoft.AspNetCore.Mvc.Abstractions' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\dapper\2.0.30\lib\netstandard2.0\Dapper.dll: warning IL2104: Assembly 'Dapper' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\dapper\2.0.30\lib\netstandard2.0\Dapper.dll: warning IL3053: Assembly 'Dapper' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\npgsql\6.0.0\lib\net6.0\Npgsql.dll: warning IL3053: Assembly 'Npgsql' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\microsoft.entityframeworkcore.relational\6.0.0\lib\net6.0\Microsoft.EntityFrameworkCore.Relational.dll: warning IL3053: Assembly 'Microsoft.EntityFrameworkCore.Relational' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\npgsql.entityframeworkcore.postgresql\6.0.0\lib\net6.0\Npgsql.EntityFrameworkCore.PostgreSQL.dll: warning IL3053: Assembly 'Npgsql.EntityFrameworkCore.PostgreSQL' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\microsoft.entityframeworkcore.sqlserver\6.0.0\lib\net6.0\Microsoft.EntityFrameworkCore.SqlServer.dll: warning IL3053: Assembly 'Microsoft.EntityFrameworkCore.SqlServer' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\microsoft.aspnetcore.mvc.newtonsoftjson\3.0.0\lib\netcoreapp3.0\Microsoft.AspNetCore.Mvc.NewtonsoftJson.dll: warning IL2104: Assembly 'Microsoft.AspNetCore.Mvc.NewtonsoftJson' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\microsoft.aspnetcore.mvc.newtonsoftjson\3.0.0\lib\netcoreapp3.0\Microsoft.AspNetCore.Mvc.NewtonsoftJson.dll: warning IL3053: Assembly 'Microsoft.AspNetCore.Mvc.NewtonsoftJson' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\system.configuration.configurationmanager\5.0.0\lib\netstandard2.0\System.Configuration.ConfigurationManager.dll: warning IL2104: Assembly 'System.Configuration.ConfigurationManager' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\microsoft.data.sqlclient\4.0.0\runtimes\win\lib\netcoreapp3.1\Microsoft.Data.SqlClient.dll: warning IL3053: Assembly 'Microsoft.Data.SqlClient' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\npgsql.entityframeworkcore.postgresql\6.0.0\lib\net6.0\Npgsql.EntityFrameworkCore.PostgreSQL.dll: warning IL2104: Assembly 'Npgsql.EntityFrameworkCore.PostgreSQL' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\microsoft.aspnetcore.app.runtime.win-x64\8.0.0-alpha.1.23058.7\runtimes\win-x64\lib\net8.0\Microsoft.AspNetCore.Mvc.DataAnnotations.dll: warning IL2104: Assembly 'Microsoft.AspNetCore.Mvc.DataAnnotations' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\microsoft.identitymodel.tokens\6.8.0\lib\netstandard2.0\Microsoft.IdentityModel.Tokens.dll: warning IL2104: Assembly 'Microsoft.IdentityModel.Tokens' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\8.0.0-alpha.1.23058.2\framework\Microsoft.CSharp.dll: warning IL3053: Assembly 'Microsoft.CSharp' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\microsoft.identitymodel.tokens\6.8.0\lib\netstandard2.0\Microsoft.IdentityModel.Tokens.dll: warning IL3053: Assembly 'Microsoft.IdentityModel.Tokens' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\microsoft.identitymodel.logging\6.8.0\lib\netstandard2.0\Microsoft.IdentityModel.Logging.dll: warning IL2104: Assembly 'Microsoft.IdentityModel.Logging' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
/_/src/libraries/System.Data.Common/src/System/Data/DataSet.cs(3519): Trim analysis warning IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter): Using member 'System.Data.DataSet.WriteXmlInternal(XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataSet.WriteXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.
/_/src/libraries/System.Data.Common/src/System/Data/DataTable.cs(6718): Trim analysis warning IL2026: System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter): Using member 'System.Data.DataTable.WriteXmlInternal(XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataTable.WriteXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.
C:\Users\eerhardt\.nuget\packages\microsoft.aspnetcore.app.runtime.win-x64\8.0.0-alpha.1.23058.7\runtimes\win-x64\lib\net8.0\Microsoft.AspNetCore.Mvc.Razor.dll: warning IL2104: Assembly 'Microsoft.AspNetCore.Mvc.Razor' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\microsoft.aspnetcore.app.runtime.win-x64\8.0.0-alpha.1.23058.7\runtimes\win-x64\lib\net8.0\Microsoft.AspNetCore.Mvc.ViewFeatures.dll: warning IL3053: Assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\8.0.0-alpha.1.23058.2\framework\System.Private.Xml.dll: warning IL3053: Assembly 'System.Private.Xml' produced AOT analysis warnings.
ILC: Trim analysis warning IL2026: System.Security.Cryptography.Xml.CryptoHelpers.CreateFromName<T>(String): Using member 'System.Security.Cryptography.CryptoConfig.CreateFromName(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.
C:\Users\eerhardt\.nuget\packages\azure.identity\1.3.0\lib\netstandard2.0\Azure.Identity.dll: warning IL2104: Assembly 'Azure.Identity' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\azure.core\1.6.0\lib\netstandard2.0\Azure.Core.dll: warning IL2104: Assembly 'Azure.Core' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
/_/src/libraries/System.Data.Common/src/System/Data/DataSet.cs(3497): Trim analysis warning IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.ReadXml(XmlReader): Using member 'System.Data.DataSet.ReadXmlSerializableInternal(XmlReader)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataSet.ReadXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.
/_/src/libraries/System.Data.Common/src/System/Data/DataTable.cs(6700): Trim analysis warning IL2026: System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.ReadXml(XmlReader): Using member 'System.Data.DataTable.ReadXmlSerializableInternal(XmlReader)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataTable.ReadXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.
C:\Users\eerhardt\.nuget\packages\microsoft.aspnetcore.app.runtime.win-x64\8.0.0-alpha.1.23058.7\runtimes\win-x64\lib\net8.0\System.Security.Cryptography.Xml.dll: warning IL2104: Assembly 'System.Security.Cryptography.Xml' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
/_/src/libraries/System.Data.Common/src/System/Data/DataSet.cs(3463): Trim analysis warning IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.GetSchema(): Using member 'System.Data.DataSet.WriteXmlSchema(DataSet,XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataSet.GetSchema uses TypeDescriptor and XmlSerialization underneath which are not trimming safe. Members from serialized types may be trimmed if not referenced directly.
/_/src/libraries/System.Data.Common/src/System/Data/DataTable.cs(6664): Trim analysis warning IL2026: System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.GetSchema(): Using member 'System.Data.DataTable.GetXmlSchema()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataTable.GetSchema uses TypeDescriptor and XmlSerialization underneath which are not trimming safe. Members from serialized types may be trimmed if not referenced directly.
/_/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationReader.cs(34): Trim analysis warning IL2026: System.Xml.Serialization.ReflectionXmlSerializationReader..cctor(): Using member 'System.Xml.Serialization.TypeScope.GetTypeDesc(Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. calls GetTypeDesc.
/_/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationReader.cs(35): Trim analysis warning IL2026: System.Xml.Serialization.ReflectionXmlSerializationReader..cctor(): Using member 'System.Xml.Serialization.TypeScope.GetTypeDesc(Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. calls GetTypeDesc.
C:\Users\eerhardt\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\8.0.0-alpha.1.23058.2\framework\System.Private.DataContractSerialization.dll: warning IL3053: Assembly 'System.Private.DataContractSerialization' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\microsoft.identity.client\4.22.0\lib\netcoreapp2.1\Microsoft.Identity.Client.dll: warning IL2104: Assembly 'Microsoft.Identity.Client' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
C:\Users\eerhardt\.nuget\packages\microsoft.aspnetcore.app.runtime.win-x64\8.0.0-alpha.1.23058.7\runtimes\win-x64\lib\net8.0\Microsoft.AspNetCore.Mvc.Razor.dll: warning IL3053: Assembly 'Microsoft.AspNetCore.Mvc.Razor' produced AOT analysis warnings.
C:\Users\eerhardt\.nuget\packages\microsoft.identity.client\4.22.0\lib\netcoreapp2.1\Microsoft.Identity.Client.dll: warning IL3053: Assembly 'Microsoft.Identity.Client' produced AOT analysis warnings.
Also linking https://github.com/npgsql/npgsql/issues/4799 here. Which is for reducing the size of Npsql under NativeAOT.
I spot checked where the compiler is spending time. I didn't see anything pathological. The app is just huge. The object file is 700 MB.
I ran it with <IlcGenerateMapFile>true</IlcGenerateMapFile>
and spot checked the generated Benchmarks.map.xml.
One thing that stands out is many instantiations involving NpgSqlRange:
Just a random sample:
__GenericDict_S_P_CoreLib_System_Runtime_CompilerServices_AsyncTaskMethodBuilder__AwaitUnsafeOnCompleted<S_P_CoreLib_System_Runtime_CompilerServices_TaskAwaiter__Npgsql_Npgsql_Internal_TypeHandlers_MultirangeHandler_1__WriteMultirange_d__13_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<Npgsql_NpgsqlTypes_NpgsqlLogSequenceNumber>>>>>>____Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<Npgsql_NpgsqlTypes_NpgsqlLogSequenceNumber>>>>>>>>
__GenericDict_S_P_CoreLib_System_Runtime_CompilerServices_AsyncTaskMethodBuilder_1<S_P_CoreLib_System_Collections_Generic_List_1<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<Npgsql_NpgsqlTypes_NpgsqlLine>>>>>>>__AwaitUnsafeOnCompleted_1<S_P_CoreLib_System_Runtime_CompilerServices_TaskAwaiter>
__writableDataS_P_CoreLib_System_Threading_Tasks_Sources_IValueTaskSource_1<S_P_CoreLib_System_Collections_Generic_List_1<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<S_P_CoreLib_System_DBNull>>>>>>>
__fatpointer_S_P_CoreLib_System_Runtime_CompilerServices_AsyncTaskMethodBuilder_1_AsyncStateMachineBox_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<Int64>>>>>>>>__Npgsql_Npgsql_Internal_TypeHandling_NpgsqlTypeHandler__Read_d__4_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<__Array<Npgsql_NpgsqlTypes_NpgsqlRange_1<Int64>>>>>>>>>>__ExecutionContextCallback
There is still a generic cycle in Npgsql that is probably contributing to this but we no longer need to abort compiling stuff due to the cycle getting too deep (so there are no messages). But the cycle probably contributes to the expansion. These generics are getting pretty deep.
The cycle(s) involve(s):
NpgSqlTypeHandler<>
MultiRangeHandler<>
MultiRangeHandler<>.ReadMultirangeArray<>
MultiRangeHandler<>.ReadMultirangeList<>
MultiRangeHandler<>.WriteMultirange<>
(so there are no messages)
Bah I was wrong. The messages are there. They just get folded into the single "NpgSql is not compatible with AOT" warning. one <TrimmerSingleWarn>false</TrimmerSingleWarn>
later, there's a bunch of these:
AOT analysis warning IL3054: Npgsql.Internal.TypeHandlers.MultirangeHandler`1<NpgsqlRange`1<NpgsqlTid>[]>.ReadMul
tirangeArray<NpgsqlRange`1<NpgsqlTid>[]>(NpgsqlReadBuffer,Int32,Boolean,FieldDescription): Generic expansion to 'System
.Runtime.CompilerServices.AsyncValueTaskMethodBuilder`1<NpgsqlRange`1<NpgsqlRange`1<NpgsqlTid>[]>[]>.Start<<ReadMultira
ngeArray>d__5`1<NpgsqlRange`1<NpgsqlTid>[],NpgsqlRange`1<NpgsqlTid>[]>>(<ReadMultirangeArray>d__5`1<NpgsqlRange`1<Npgsq
lTid>[],NpgsqlRange`1<NpgsqlTid>[]>&)' was aborted due to generic recursion. An exception will be thrown at runtime if
this codepath is ever reached. Generic recursion also negatively affects compilation speed and the size of the compilat
ion output. It is advisable to remove the source of the generic recursion by restructuring the program around the sourc
e of recursion. The source of generic recursion might include: 'Npgsql.Internal.TypeHandling.NpgsqlTypeHandler`1', 'Npg
sql.Internal.TypeHandlers.MultirangeHandler`1', 'Npgsql.Internal.TypeHandlers.MultirangeHandler`1.<ReadMultirangeArray>
d__5`1', 'Npgsql.Internal.TypeHandlers.MultirangeHandler`1.<ReadMultirangeList>d__7`1', 'Npgsql.Internal.TypeHandlers.M
ultirangeHandler`1.<WriteMultirange>d__13`1'
The messages are there. They just get folded into the single "NpgSql is not compatible with AOT" warning.
Is that correct/expected behavior? These messages aren't warnings, and they seem different than "normal" AOT warnings. So why should they get folded into the single warning?
The messages are there. They just get folded into the single "NpgSql is not compatible with AOT" warning.
Is that correct/expected behavior? These messages aren't warnings, and they seem different than "normal" AOT warnings. So why should they get folded into the single warning?
It feels the category is the same - it's code that is fine when one is JIT or interpreter based, but can be problematic with AOT (it may throw exceptions at runtime and as a side effect also makes things bigger/slower to compiler). It's an AOT warning.
It takes more than 8 minutes to build a medium sized application in NativeAoT compared to 15s without (both as self-contained).
Project
https://github.com/aspnet/Benchmarks/tree/main/src/Benchmarks
Build command line
Build log