Skip to content

Commit

Permalink
Index: inlined node equality
Browse files Browse the repository at this point in the history
  • Loading branch information
luithefirst committed Sep 18, 2024
1 parent 342335a commit fa77c38
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/FSharp.Data.Adaptive/Datastructures/Index.fs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type IndexNode =

/// initially we increment the distance by Uint64.MaxValue/2
let mutable distance =
if next = x then UInt64.MaxValue
if Object.ReferenceEquals(next, x) then UInt64.MaxValue
else next.Tag - x.Tag

// we're out of luck and there's no space for an additional node.
Expand All @@ -94,7 +94,7 @@ type IndexNode =
member x.Delete() =
let prev = x.Prev
Monitor.Enter prev
if prev.Next <> x then // NOTE: prev.Next might point to an inserted node between after lock has been aquired
if not (Object.ReferenceEquals(prev.Next, x)) then // NOTE: prev.Next might point to an inserted node between after lock has been aquired
Monitor.Exit prev
x.Delete()
else
Expand Down Expand Up @@ -166,7 +166,7 @@ type Index private(real : IndexNode) =
Monitor.Enter real
let res =
let next = real.Next
if next <> real.Root then
if not (Object.ReferenceEquals(next, real.Root)) then
Monitor.Enter next
next.RefCount <- next.RefCount + 1
Monitor.Exit next
Expand All @@ -179,12 +179,12 @@ type Index private(real : IndexNode) =
member x.Before() =
let prev = real.Prev
Monitor.Enter prev
if prev.Next <> real then // NOTE: prev.Next might point to an inserted node between or be null if it just has been deleted
if not (Object.ReferenceEquals(prev.Next, real)) then // NOTE: prev.Next might point to an inserted node between or be null if it just has been deleted
Monitor.Exit prev
x.Before()
else
let res =
if prev = real.Root then
if Object.ReferenceEquals(prev, real.Root) then
prev.InsertAfter() |> Index
else
prev.RefCount <- prev.RefCount + 1
Expand All @@ -199,7 +199,7 @@ type Index private(real : IndexNode) =
Monitor.Enter l
let res =
let next = l.Next
if next = r then
if Object.ReferenceEquals(next, r) then
l.InsertAfter() |> Index
else
Monitor.Enter next
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ type IndexEqualsBenchmarks() =
//|--------- |------------- |---------- |--------:|---------:|---------:|------------:|------------:|-----------:|
//| Garbage0 | 5000000 | 100 | 1.531 s | 0.0040 s | 0.0035 s | 169000.0000 | 168000.0000 | 1016.93 MB |

// + inlined node equality (and other small changes, however those do not have any significant effect)
//| Method | GarbageCount | ListCount | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
//|--------- |------------- |---------- |--------:|---------:|---------:|------------:|------------:|-----------:|
//| Garbage0 | 5000000 | 100 | 1.479 s | 0.0052 s | 0.0044 s | 170000.0000 | 169000.0000 | 1017.98 MB |

[<MemoryDiagnoser>]
[<InProcess>]
type IndexGarbageBenchmarks() =
Expand Down

0 comments on commit fa77c38

Please sign in to comment.