Skip to content

Commit 5c8b1f5

Browse files
xperiandriclaude
andcommitted
fixup! feat: IndexedList and IIndexedList modules with the vocabulary of the FSharp.Core List module
The remark of `IndexedList.rev` and the comment in its body said that the function is about 2.5 times faster than `ImmutableList.Reverse` at 100 000 elements, with the same allocation. Measured against the 1.0.0 `reverse`, which calls `Reverse`, at 100 000 integers (Release, .NET 10, the median of 15 rounds), `rev` takes about 3 ms and `Reverse` about 23 ms, and `rev` allocates the copy of the elements in addition (5.2 MB against 4.8 MB). Only the remark and the comment change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent c0a7b72 commit 5c8b1f5

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎src/FSharp.Collections.Immutable/IndexedList/IndexedList.fs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,9 @@ let replaceWith (comparer : IEqualityComparer<'T>) (oldValue : 'T) (newValue : '
628628

629629
[<CompiledName "Reverse">]
630630
let rev (list : IndexedList<'T>) =
631-
// A copy reversed in place and a new balanced tree are about 2.5 times faster than ImmutableList.Reverse at 100 000
632-
// elements, with the same allocation (ADR 0001, D5); the copy is fresh, so nobody else sees it change
631+
// A copy reversed in place and a new balanced tree are about 8 times faster than ImmutableList.Reverse at 100 000
632+
// integers (about 3 ms against 23 ms), and the copy is the only extra allocation (ADR 0001, D5); the copy is fresh,
633+
// so nobody else sees it change
633634
let array = Snapshot.ofSeq (nameof list) list
634635
Array.Reverse array
635636
ofFreshArray array

‎src/FSharp.Collections.Immutable/IndexedList/IndexedList.fsi‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,8 +1223,9 @@ val replaceWith : comparer : IEqualityComparer<'T> -> oldValue : 'T -> newValue
12231223
/// O(n). The function copies the elements to an array, reverses it with
12241224
/// <see cref="M:System.Array.Reverse``1(``0[])"/> and builds a new tree with
12251225
/// <see cref="M:System.Collections.Immutable.ImmutableList.CreateRange``1(System.Collections.Generic.IEnumerable{``0})"/>.
1226-
/// At 100 000 elements, this is about 2.5 times faster than
1227-
/// <see cref="M:System.Collections.Immutable.ImmutableList`1.Reverse"/>, with the same allocation.
1226+
/// At 100 000 integers, this takes about 3 ms where
1227+
/// <see cref="M:System.Collections.Immutable.ImmutableList`1.Reverse"/> takes about 23 ms; the copy of the elements is
1228+
/// the only extra allocation.
12281229
/// </remarks>
12291230
[<CompiledName "Reverse">]
12301231
val rev : list : IndexedList<'T> -> IndexedList<'T>

0 commit comments

Comments
 (0)