Skip to content

Commit

Permalink
Fix deeply-nested task issue, which is now 'just fine' since we dropp…
Browse files Browse the repository at this point in the history
…ed Task.Delay
  • Loading branch information
abelbraaksma committed Oct 13, 2022
1 parent d7643ff commit 8b34b9d
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/FSharpy.TaskSeq.Test/TaskSeq.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,25 @@ let ``CE taskSeq with nested yield!`` () = task {
}

[<Fact>]
let ``CE taskSeq with nested deeply yield! perf test`` () = task {
let ``CE taskSeq with nested deeply yield! perf test 8521 nested tasks`` () = task {
let control = seq {
yield! [ 1..10 ]

// original:
// yield! Seq.concat <| Seq.init 2145 (fun _ -> [ 1; 2 ])
yield! Seq.concat <| Seq.init 120 (fun _ -> [ 1; 2 ])
yield! Seq.concat <| Seq.init 4251 (fun _ -> [ 1; 2 ])
//yield! Seq.concat <| Seq.init 120 (fun _ -> [ 1; 2 ])
}

let createTasks = createDummyTaskSeqWith 1L<µs> 10L<µs>
// FIXME: it appears that deeply nesting adds to performance degradation, need to benchmark/profile this
// probably cause: since this is *fast* with DirectTask, the reason is likely the way the Task.Delay causes
// *many* subtasks to be delayed, resulting in exponential delay. Reason: max accuracy of Delay is about 15ms (!)

// RESOLUTION: seems to have been caused by erratic Task.Delay which has only a 15ms resolution
let tskSeq = taskSeq {
yield! createTasks 10

// nestings amount to 2145 sequences of [1;2]
// nestings amount to 8512 sequences of [1;2]
for i in 0..2 do
yield! createTasks 2

Expand All @@ -87,28 +89,27 @@ let ``CE taskSeq with nested deeply yield! perf test`` () = task {

for i in 0..2 do
yield! createTasks 2
// stopping here, at a total 250 nested taskSeq
// add the below to get to 4300

//for i in 0..2 do
// yield! createTasks 2
for i in 0..2 do
yield! createTasks 2

for i in 0..2 do
yield! createTasks 2

// for i in 0..2 do
// yield! createTasks 2
for i in 0..2 do
yield! createTasks 2

//for i in 0..2 do
// yield! createTasks 2
for i in 0..2 do
yield! createTasks 2

// for i in 0..2 do
// yield! createTasks 2
for i in 0..2 do
yield! createTasks 2

// for i in 0..2 do
// yield! createTasks 2
yield! TaskSeq.empty
}

let! data = tskSeq |> TaskSeq.toListAsync
data |> List.length |> should equal 250
data |> List.length |> should equal 8512
data |> should equal (List.ofSeq control)
}

Expand Down

0 comments on commit 8b34b9d

Please sign in to comment.