-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[libs][iOS] Unify System.Linq.Expression.dll
build for all platforms
#88723
Conversation
Tagging subscribers to this area: @cston Issue DetailsThis PR contributes to fixing how Disabling constant propagation during library build time minimally affects the library size, which can be seen from the following measurements:
Furthermore, since constant propagation is always enabled during trimming / app deployment, the end effect regarding final app size is unchanged.
|
/cc: @steveisok @akoeplinger |
@kotlarmilos once this gets merged in, the smoke tests for |
src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj
Outdated
Show resolved
Hide resolved
If I'm reading this right the only thing special left for iDevices is this part: Does this do anything with IPConstProp disabled? It's a substitution that only applies during library build. If it doesn't do anything, we should delete the special iDevices build and basically roll back the csproj part of #54970. |
It still has an effect, even with I agree that essentially during app deployment the same thing would happen, but I suppose it was decided not to ship the code which will never going to be supported on such platforms. Additionally, as I posted in: #87924 (comment) excluding the library build time substitution will also bump the size of the assembly by ~100kb (which affects nuget/workload size - not by much though :) ) @steveisok what do you think? |
I'm fine with carrying extra size. An extra 100k is not significant. |
…xpression.dll on all platforms
eedac0f
to
2e8d85b
Compare
System.Linq.Expression.dll
build for all platforms
Trying to unify the library build got me thinking that for Mono: runtime/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/LambdaExpression.cs Line 29 in d361507
should be instead: public static bool CanCompileToIL => RuntimeFeature.IsDynamicCodeCompiled; Because when Mono interpreter is enabled the |
@@ -1,22 +1,14 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-maccatalyst</TargetFrameworks> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-maccatalyst</TargetFrameworks> | |
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework> |
We don't need to multi-target this project anymore since we no longer have differences between these builds.
This is always a tough decision. I don't think there is a straight forward answer. In some cases in Mono (for example WASM), I found that using interpreted IL was faster than using Reflection. See the discussion and numbers in #38693 (comment). So the answer is "it depends". It depends if Mono interpreter (the only thing today where these bools will be different) generating IL through Ref.Emit and then interpreting it is faster/better than using the Reflection fallback path. For System.Text.Json Serializer on WASM, we found that Ref.Emit was faster, so we still use it even though It would be good to test/measure it. |
There are related discussions here: #17973 - this is about ability of third-party code to query whether LINQ expressions are going to be compiled. Some libraries like Newtonsoft use LINQ expressions to make high performance serializers (hoping the expression is compiled to IL). But if it's interpreted, they're better off using reflection. They need a way to find out at runtime whether this is going to be compiled or interpreted. #79726 - this is about exposing it as a public feature switch that people can set to get more trimming. For example, the SDK could set this feature switch to trim Ref.Emit backend when I don't think we should change this to |
There is another scenario which is affected with this change. |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
System.Linq.Expression.dll
build for all platformsSystem.Linq.Expression.dll
build for all platforms
/azp run runtime-maccatalyst,runtime-ioslikesimulator |
Azure Pipelines successfully started running 2 pipeline(s). |
Check out #85759. This has been fixed on iOS devices (allow an infinite number of trampolines) but is not ported to all platforms like the ios simulators. I think you can just bump them. |
Yeah I've just bumped them before the last run. Thanks! |
/azp run runtime-maccatalyst |
Azure Pipelines successfully started running 1 pipeline(s). |
After some testing on At the bottom of the following log it can be seen that |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
Reflection is always faster than interpreted LINQ (I did not mean Ref.Emit interpreter, I meant the LINQ |
Failures are not related. |
Description
This PR removes special builds of
System.Linq.Expression.dll
for iOS-like platforms enabling us to ship a single assembly for all platforms, and to have better compatibility between our AOT engines.These changes contribute towards fixing how the library is built for iOS-like platforms preventing conditional variables like:
CanEmitObjectArrayDelegate
to be removed from the library during library build time, which are required to be present for AOT compilation (during app deployment) with NativeAOT, as discussed in: #87924Changes
The following changes are introduced:
Measurements
Unifying how the library is built for all platforms affects the library size, which can be seen from the following measurements:
The increase in size of
25%
comes from the fact thatRef.Emit
code paths are now included in the assembly. However, this does not cause any size regressions for applications built for iOS-like platforms, because during app deployment the unsupported code paths (likeRef.Emit
) will be removed during trimming due to:runtime/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/LambdaExpression.cs
Line 29 in d361507
as
IsDynamicCodeSupported=false
on these platforms.Summary
This PR affects the following:
System.Linq.Expression.dll
for iOS-like platforms is increased by~113Kb
(~25%
)UseInterpreter=true
configurations with Mono (when interpreter is used as a fallback on iOS-like platforms) are now interpretingRef.Emit
generated code instead of using ReflectionRef.Emit
backend (which should not be a problem as we do not recommend this setup for app deployment in the first place)The apps deployed with standard Mono fullAOT configurations for iOS-like platforms should not be affected by this change once: xamarin/xamarin-macios#18555 gets merged in.