Skip to content

[Breaking change]: Removed Boolean-based overloads of ToFrozenDictionary / ToFrozenSet #35960

@stephentoub

Description

@stephentoub

Description

Overloads of ToFrozenDictionary and ToFrozenSet in .NET 8 Preview 1 allowed for a Boolean optimizeForReading argument to be supplied. These overloads have been removed in .NET 8 Preview 7.

Version

.NET 8 Preview 7

Previous behavior

When calling overloads of ToFrozenDictionary and ToFrozenSet that included optimizeForReading and specifying true, the implementations would take more time to construct instances of FrozenDictionary<,> and FrozenSet<> that were optimized for the spead of performing lookups and reading data from the collections, at the expense of potentially much more time spent in the ToFrozenDictionary and ToFrozenSet calls.

New behavior

These overloads have been removed. Now all of the ToFrozenDictionary and ToFrozenSet spend extra time to construct a collection optimized for reading.

dotnet/runtime#87988

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
  • Behavioral change: Existing binaries may behave differently at run time.

Reason for change

Construction performance has been optimized such that it now no longer makes sense to differentiate modes, with ToFrozenDictionary and ToFrozenSet now always producing implementations optimized for reading, regardless of which overload is used.

Recommended action

If you're calling the overloads that accepted a Boolean parameter, remove the Boolean argument from the call site.

Feature area

Core .NET libraries

Affected APIs

namespace System.Collections.Frozen;

public static class FrozenDictionary
{
-    public static FrozenDictionary<TKey, TValue> ToFrozenDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, bool optimizeForReading) where TKey : notnull;
-    public static FrozenDictionary<TKey, TValue> ToFrozenDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, IEqualityComparer<TKey>? comparer, bool optimizeForReading) where TKey : notnull
}

public static class FrozenSet
{
-    public static FrozenSet<T> ToFrozenSet<T>(this IEnumerable<T> source, bool optimizeForReading);
-    public static FrozenSet<T> ToFrozenSet<T>(this IEnumerable<T> source, IEqualityComparer<T>? comparer, bool optimizeForReading);
}

Associated WorkItem - 118217

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 8Work items for the .NET 8 release📌 seQUESTeredIdentifies that an issue has been imported into Quest.binary incompatibleExisting binaries may encounter a breaking change in behavior.breaking-changeIndicates a .NET Core breaking changesource incompatibleSource code may encounter a breaking change in behavior when targeting the new version.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions