From 835f5b4fb87e461a33aa54f1d5a06d533f5f9e44 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 9 Feb 2021 09:30:41 -0500 Subject: [PATCH] Enable size-optimized LINQ build for Browser (#47918) * Enable size-optimized LINQ build for Browser Re-enable the size-optimized variant of LINQ and use it for the Browser build of the library. * Opt more targets into size optimizations, per PR feedback --- .../System/Collections/Generic/LargeArrayBuilder.SizeOpt.cs | 2 -- .../Common/tests/TestUtilities/System/PlatformDetection.cs | 3 +++ src/libraries/System.Linq/src/System.Linq.csproj | 12 ++++++++++-- src/libraries/System.Linq/tests/ConcatTests.cs | 2 +- src/libraries/System.Linq/tests/EmptyPartitionTests.cs | 4 ++-- src/libraries/System.Linq/tests/OrderedSubsetting.cs | 2 +- src/libraries/System.Linq/tests/RangeTests.cs | 4 ++-- src/libraries/System.Linq/tests/SelectManyTests.cs | 2 +- src/libraries/System.Linq/tests/TakeTests.cs | 2 +- 9 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/libraries/Common/src/System/Collections/Generic/LargeArrayBuilder.SizeOpt.cs b/src/libraries/Common/src/System/Collections/Generic/LargeArrayBuilder.SizeOpt.cs index 4ec34a7..181d2fd 100644 --- a/src/libraries/Common/src/System/Collections/Generic/LargeArrayBuilder.SizeOpt.cs +++ b/src/libraries/Common/src/System/Collections/Generic/LargeArrayBuilder.SizeOpt.cs @@ -35,8 +35,6 @@ namespace System.Collections.Generic } } - public void SlowAdd(T item) => _builder.Add(item); - public T[] ToArray() => _builder.ToArray(); public CopyPosition CopyTo(CopyPosition position, T[] array, int arrayIndex, int count) diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index dfd4ba7..f56404f 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -50,6 +50,9 @@ namespace System public static bool IsThreadingSupported => !IsBrowser; public static bool IsBinaryFormatterSupported => !IsBrowser; + public static bool IsSpeedOptimized => !IsSizeOptimized; + public static bool IsSizeOptimized => IsBrowser || IsAndroid || IsiOS || IstvOS; + public static bool IsBrowserDomSupported => GetIsBrowserDomSupported(); public static bool IsNotBrowserDomSupported => !IsBrowserDomSupported; diff --git a/src/libraries/System.Linq/src/System.Linq.csproj b/src/libraries/System.Linq/src/System.Linq.csproj index ea58568..2f81469 100644 --- a/src/libraries/System.Linq/src/System.Linq.csproj +++ b/src/libraries/System.Linq/src/System.Linq.csproj @@ -1,9 +1,17 @@ - $(NetCoreAppCurrent) + $(NetCoreAppCurrent);$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-Android;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS enable + true - + + + + + + + diff --git a/src/libraries/System.Linq/tests/ConcatTests.cs b/src/libraries/System.Linq/tests/ConcatTests.cs index 256fea4..6209d84 100644 --- a/src/libraries/System.Linq/tests/ConcatTests.cs +++ b/src/libraries/System.Linq/tests/ConcatTests.cs @@ -244,7 +244,7 @@ namespace System.Linq.Tests yield return new object[] { Enumerable.Range(0, 500).Select(i => Enumerable.Repeat(i, 1)).Reverse() }; } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsSpeedOptimized))] public void CountOfConcatIteratorShouldThrowExceptionOnIntegerOverflow() { var supposedlyLargeCollection = new DelegateBasedCollection { CountWorker = () => int.MaxValue }; diff --git a/src/libraries/System.Linq/tests/EmptyPartitionTests.cs b/src/libraries/System.Linq/tests/EmptyPartitionTests.cs index 7417cbe..c98884e 100644 --- a/src/libraries/System.Linq/tests/EmptyPartitionTests.cs +++ b/src/libraries/System.Linq/tests/EmptyPartitionTests.cs @@ -29,7 +29,7 @@ namespace System.Linq.Tests Assert.True(ReferenceEquals(GetEmptyPartition(), GetEmptyPartition())); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsSpeedOptimized))] [SkipOnTargetFramework(~TargetFrameworkMonikers.Netcoreapp, ".NET Core returns the instance as an optimization")] public void SkipSame() { @@ -37,7 +37,7 @@ namespace System.Linq.Tests Assert.Same(empty, empty.Skip(2)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsSpeedOptimized))] [SkipOnTargetFramework(~TargetFrameworkMonikers.Netcoreapp, ".NET Core returns the instance as an optimization")] public void TakeSame() { diff --git a/src/libraries/System.Linq/tests/OrderedSubsetting.cs b/src/libraries/System.Linq/tests/OrderedSubsetting.cs index 1e28214..f4ec16f 100644 --- a/src/libraries/System.Linq/tests/OrderedSubsetting.cs +++ b/src/libraries/System.Linq/tests/OrderedSubsetting.cs @@ -224,7 +224,7 @@ namespace System.Linq.Tests Assert.Equal(Enumerable.Range(10, 1), ordered.Take(11).Skip(10)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsSpeedOptimized))] [SkipOnTargetFramework(~TargetFrameworkMonikers.Netcoreapp, "This fails with an OOM, as it iterates through the large array. See https://github.com/dotnet/corefx/pull/6821.")] public void TakeAndSkip_DoesntIterateRangeUnlessNecessary() { diff --git a/src/libraries/System.Linq/tests/RangeTests.cs b/src/libraries/System.Linq/tests/RangeTests.cs index 83527a9..68894cf 100644 --- a/src/libraries/System.Linq/tests/RangeTests.cs +++ b/src/libraries/System.Linq/tests/RangeTests.cs @@ -211,14 +211,14 @@ namespace System.Linq.Tests Assert.Equal(-100, Enumerable.Range(-100, int.MaxValue).FirstOrDefault()); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsSpeedOptimized))] [SkipOnTargetFramework(~TargetFrameworkMonikers.Netcoreapp, ".NET Core optimizes Enumerable.Range().Last(). Without this optimization, this test takes a long time. See https://github.com/dotnet/corefx/pull/2401.")] public void Last() { Assert.Equal(1000000056, Enumerable.Range(57, 1000000000).Last()); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsSpeedOptimized))] [SkipOnTargetFramework(~TargetFrameworkMonikers.Netcoreapp, ".NET Core optimizes Enumerable.Range().LastOrDefault(). Without this optimization, this test takes a long time. See https://github.com/dotnet/corefx/pull/2401.")] public void LastOrDefault() { diff --git a/src/libraries/System.Linq/tests/SelectManyTests.cs b/src/libraries/System.Linq/tests/SelectManyTests.cs index 45c5a7d..50d97f0 100644 --- a/src/libraries/System.Linq/tests/SelectManyTests.cs +++ b/src/libraries/System.Linq/tests/SelectManyTests.cs @@ -464,7 +464,7 @@ namespace System.Linq.Tests return lengths.SelectMany(l => lengths, (l1, l2) => new object[] { l1, l2 }); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsSpeedOptimized))] [SkipOnTargetFramework(~TargetFrameworkMonikers.Netcoreapp, ".NET Core optimizes SelectMany and throws an OverflowException. On the .NET Framework this takes a long time. See https://github.com/dotnet/corefx/pull/13942.")] [InlineData(new[] { int.MaxValue, 1 })] [InlineData(new[] { 2, int.MaxValue - 1 })] diff --git a/src/libraries/System.Linq/tests/TakeTests.cs b/src/libraries/System.Linq/tests/TakeTests.cs index a9580fb..239ec1f 100644 --- a/src/libraries/System.Linq/tests/TakeTests.cs +++ b/src/libraries/System.Linq/tests/TakeTests.cs @@ -459,7 +459,7 @@ namespace System.Linq.Tests Assert.Equal(taken, taken); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsSpeedOptimized))] [InlineData(1000)] [InlineData(1000000)] [InlineData(int.MaxValue)] -- 2.7.4