diff --git a/docs/core/compatibility/3.1-5.0.md b/docs/core/compatibility/3.1-5.0.md index 0e37cfe65a630..f8e55adf05266 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.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) @@ -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..3ed39a85e1229 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.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 | @@ -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..92708422952d0 --- /dev/null +++ b/includes/core-changes/corefx/5.0/orderby-firstordefault-complexity-increase.md @@ -0,0 +1,46 @@ +### Complexity of LINQ OrderBy.First{OrDefault} increased + +The implementation of `.` and `.` has changed, resulting in increased complexity for the operation. + +#### Change description + +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 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. For more information, see [this dotnet/runtime issue](https://github.com/dotnet/runtime/issues/31554). + +#### Version introduced + +5.0 + +#### Recommended action + +No action is required on the developer's part. + +#### Category + +Core .NET libraries + +#### Affected APIs + +- +- +- +- + +