Skip to content

List.Equals performs full structural comparison for the same object. #14672

Closed as not planned
@safesparrow

Description

@safesparrow

F# list's List.Equals always performs full structural comparison, even if the two objects being compared are the same object.

Repro steps

open System.Diagnostics

let swList = Stopwatch.StartNew()
let l = [1..1000000]
for i in [1..100] do
    if l.Equals(l) = false then
        failwith "Not equal"
printfn $"List: {swList.Elapsed}"

let swArray = Stopwatch.StartNew()
let a = [|1..1000000|]
for i in [1..100] do
    if a.Equals(a) = false then
        failwith "Not equal"
printfn $"Array: {swArray.Elapsed}"

Expected behavior

List and array-based code should be equally quick.

Actual behavior
List is much slower:

List: 00:00:02.2389815
Array: 00:00:00.0114506

Known workarounds

  • Use object equality explicitly before using List.Equals
  • Use other collection types

Related information
#9348
#6175

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions