From 043f3b7a1451dfb53e7d6fe62bb6fa69230f0a02 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Mon, 10 Aug 2020 16:08:14 -0700 Subject: [PATCH 1/4] Fixes #19683 --- docs/core/compatibility/3.1-5.0.md | 5 +++ docs/core/compatibility/corefx.md | 5 +++ ...erby-firstordefault-complexity-increase.md | 40 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md diff --git a/docs/core/compatibility/3.1-5.0.md b/docs/core/compatibility/3.1-5.0.md index 0e37cfe65a630..ebc7093e05d7c 100644 --- a/docs/core/compatibility/3.1-5.0.md +++ b/docs/core/compatibility/3.1-5.0.md @@ -122,6 +122,7 @@ If you're migrating from version 3.1 of .NET Core, ASP.NET Core, or EF Core to v ## Core .NET libraries +- [Complexity of LINQ OrderBy increased](#complexity-of-linq-orderby-increased) - [IntPtr and UIntPtr implement IFormattable](#intptr-and-uintptr-implement-iformattable) - [PrincipalPermissionAttribute is obsolete as error](#principalpermissionattribute-is-obsolete-as-error) - [BinaryFormatter serialization methods are obsolete and prohibited in ASP.NET apps](#binaryformatter-serialization-methods-are-obsolete-and-prohibited-in-aspnet-apps) @@ -133,6 +134,10 @@ If you're migrating from version 3.1 of .NET Core, ASP.NET Core, or EF Core to v - [CounterSet.CreateCounterSetInstance now throws InvalidOperationException if instance already exist](#countersetcreatecountersetinstance-now-throws-invalidoperationexception-if-instance-already-exists) - [Microsoft.DotNet.PlatformAbstractions package removed](#microsoftdotnetplatformabstractions-package-removed) +[!INCLUDE [orderby-firstordefault-complexity-increase](../../../includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md)] + +*** + [!INCLUDE [intptr-uintptr-implement-iformattable](../../../includes/core-changes/corefx/5.0/intptr-uintptr-implement-iformattable.md)] *** diff --git a/docs/core/compatibility/corefx.md b/docs/core/compatibility/corefx.md index 8b553ead7a476..367bf8bac4fb5 100644 --- a/docs/core/compatibility/corefx.md +++ b/docs/core/compatibility/corefx.md @@ -11,6 +11,7 @@ The following breaking changes are documented on this page: | Breaking change | Version introduced | | - | :-: | +| [Complexity of LINQ OrderBy increased](#complexity-of-linq-orderby-increased) | 5.0 | | [IntPtr and UIntPtr implement IFormattable](#intptr-and-uintptr-implement-iformattable) | 5.0 | | [PrincipalPermissionAttribute is obsolete as error](#principalpermissionattribute-is-obsolete-as-error) | 5.0 | | [BinaryFormatter serialization methods are obsolete and prohibited in ASP.NET apps](#binaryformatter-serialization-methods-are-obsolete-and-prohibited-in-aspnet-apps) | 5.0 | @@ -40,6 +41,10 @@ The following breaking changes are documented on this page: ## .NET 5.0 +[!INCLUDE [orderby-firstordefault-complexity-increase](../../../includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md)] + +*** + [!INCLUDE [intptr-uintptr-implement-iformattable](../../../includes/core-changes/corefx/5.0/intptr-uintptr-implement-iformattable.md)] *** diff --git a/includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md b/includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md new file mode 100644 index 0000000000000..4a06a8b1b45aa --- /dev/null +++ b/includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md @@ -0,0 +1,40 @@ +### Complexity of LINQ OrderBy increased + +The implementation of has changed, resulting in an increased complexity. + +#### Change description + +In .NET Core 1.x - 3.x, `OrderBy().First()` and `OrderBy().FirstOrDefault()` operate with `O(N)` complexity. Since only the first (or default) element is required, only one enumeration is required to find it. However, the supplied predicate is invoked exactly `N` times, where `N` is the length of the sequence. + +In .NET 5.0 and later versions, a [change was made](https://github.com/dotnet/runtime/pull/36643) such that `OrderBy().First()` and `OrderBy().FirstOrDefault()` operate with `O(N log N)` complexity. However, the predicate may be invoked less than `N` times, which is more important for overall performance. + +> [!NOTE] +> This change matches the implementation and complexity of the operation in .NET Framework. + +#### Reason for change + +The cost of potentially invoking the predicate more times is too great, even with the benefit of a lower overall complexity. + +#### Version introduced + +5.0 + +#### Recommended action + +No action is required. + +#### Category + +Core .NET libraries + +#### Affected APIs + +- + + From 7143ae6453d6e3ff35274a7e2dd75eb9b269ac61 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Tue, 11 Aug 2020 06:45:07 -0700 Subject: [PATCH 2/4] reword reason --- .../corefx/5.0/orderby-firstordefault-complexity-increase.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md b/includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md index 4a06a8b1b45aa..a839c393f3a8f 100644 --- a/includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md +++ b/includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md @@ -13,7 +13,7 @@ In .NET 5.0 and later versions, a [change was made](https://github.com/dotnet/ru #### Reason for change -The cost of potentially invoking the predicate more times is too great, even with the benefit of a lower overall complexity. +The benefit of invoking the predicate fewer times outweighs a lower overall complexity, so the implementation that was introduced in .NET Core 1.0 was reverted. #### Version introduced From 7d61a896bb3692f6ca5491d2513b37753b17aaf2 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Tue, 11 Aug 2020 15:41:21 -0700 Subject: [PATCH 3/4] add orderbydescending and predicate info --- ...derby-firstordefault-complexity-increase.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md b/includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md index a839c393f3a8f..92708422952d0 100644 --- a/includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md +++ b/includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md @@ -1,19 +1,19 @@ -### Complexity of LINQ OrderBy increased +### Complexity of LINQ OrderBy.First{OrDefault} increased -The implementation of has changed, resulting in an increased complexity. +The implementation of `.` and `.` has changed, resulting in increased complexity for the operation. #### Change description -In .NET Core 1.x - 3.x, `OrderBy().First()` and `OrderBy().FirstOrDefault()` operate with `O(N)` complexity. Since only the first (or default) element is required, only one enumeration is required to find it. However, the supplied predicate is invoked exactly `N` times, where `N` is the length of the sequence. +In .NET Core 1.x - 3.x, calling or followed by or operates with `O(N)` complexity. Since only the first (or default) element is required, only one enumeration is required to find it. However, the predicate that's supplied to or is invoked exactly `N` times, where `N` is the length of the sequence. -In .NET 5.0 and later versions, a [change was made](https://github.com/dotnet/runtime/pull/36643) such that `OrderBy().First()` and `OrderBy().FirstOrDefault()` operate with `O(N log N)` complexity. However, the predicate may be invoked less than `N` times, which is more important for overall performance. +In .NET 5.0 and later versions, a [change was made](https://github.com/dotnet/runtime/pull/36643) such that calling or followed by or operates with `O(N log N)` complexity instead of `O(N)` complexity. However, the predicate that's supplied to or may be invoked *less* than `N` times, which is more important for overall performance. > [!NOTE] > This change matches the implementation and complexity of the operation in .NET Framework. #### Reason for change -The benefit of invoking the predicate fewer times outweighs a lower overall complexity, so the implementation that was introduced in .NET Core 1.0 was reverted. +The benefit of invoking the predicate fewer times outweighs a lower overall complexity, so the implementation that was introduced in .NET Core 1.0 was reverted. For more information, see [this dotnet/runtime issue](https://github.com/dotnet/runtime/issues/31554). #### Version introduced @@ -21,7 +21,7 @@ The benefit of invoking the predicate fewer times outweighs a lower overall comp #### Recommended action -No action is required. +No action is required on the developer's part. #### Category @@ -30,11 +30,17 @@ Core .NET libraries #### Affected APIs - +- +- +- From 297fa79ac2d081a12fcbd598de0e48ffb1859546 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Tue, 11 Aug 2020 15:47:48 -0700 Subject: [PATCH 4/4] fix bookmarks --- docs/core/compatibility/3.1-5.0.md | 2 +- docs/core/compatibility/corefx.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/core/compatibility/3.1-5.0.md b/docs/core/compatibility/3.1-5.0.md index ebc7093e05d7c..f8e55adf05266 100644 --- a/docs/core/compatibility/3.1-5.0.md +++ b/docs/core/compatibility/3.1-5.0.md @@ -122,7 +122,7 @@ If you're migrating from version 3.1 of .NET Core, ASP.NET Core, or EF Core to v ## Core .NET libraries -- [Complexity of LINQ OrderBy increased](#complexity-of-linq-orderby-increased) +- [Complexity of LINQ OrderBy.First{OrDefault} increased](#complexity-of-linq-orderbyfirstordefault-increased) - [IntPtr and UIntPtr implement IFormattable](#intptr-and-uintptr-implement-iformattable) - [PrincipalPermissionAttribute is obsolete as error](#principalpermissionattribute-is-obsolete-as-error) - [BinaryFormatter serialization methods are obsolete and prohibited in ASP.NET apps](#binaryformatter-serialization-methods-are-obsolete-and-prohibited-in-aspnet-apps) diff --git a/docs/core/compatibility/corefx.md b/docs/core/compatibility/corefx.md index 367bf8bac4fb5..3ed39a85e1229 100644 --- a/docs/core/compatibility/corefx.md +++ b/docs/core/compatibility/corefx.md @@ -11,7 +11,7 @@ The following breaking changes are documented on this page: | Breaking change | Version introduced | | - | :-: | -| [Complexity of LINQ OrderBy increased](#complexity-of-linq-orderby-increased) | 5.0 | +| [Complexity of LINQ OrderBy.First{OrDefault} increased](#complexity-of-linq-orderbyfirstordefault-increased) | 5.0 | | [IntPtr and UIntPtr implement IFormattable](#intptr-and-uintptr-implement-iformattable) | 5.0 | | [PrincipalPermissionAttribute is obsolete as error](#principalpermissionattribute-is-obsolete-as-error) | 5.0 | | [BinaryFormatter serialization methods are obsolete and prohibited in ASP.NET apps](#binaryformatter-serialization-methods-are-obsolete-and-prohibited-in-aspnet-apps) | 5.0 |