Skip to content

Commit abd88f6

Browse files
authored
Merge pull request #284 from fsprojects/repo-assist/perf-init-remove-lazy-2026-03-2c6e1b4098c5e418
[Repo Assist] perf: remove unnecessary Lazy allocation in TaskSeq.init per iteration
2 parents b36127a + 6d2dd11 commit abd88f6

File tree

6 files changed

+17
-23
lines changed

6 files changed

+17
-23
lines changed

global.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sdk": {
3+
"version": "10.0.103",
4+
"rollForward": "minor"
5+
}
6+
}

release-notes.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

22
Release notes:
3+
4+
0.5.0
5+
- update engineering to .NET 9/10
6+
37
0.4.0
48
- overhaul all doc comments, add exceptions, improve IDE quick-info experience, #136, #220, #234
59
- new surface area functions, fixes #208:

src/FSharp.Control.TaskSeq.SmokeTests/FSharp.Control.TaskSeq.SmokeTests.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
66
</PropertyGroup>
77

src/FSharp.Control.TaskSeq.Test/FSharp.Control.TaskSeq.Test.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
66
</PropertyGroup>
77

src/FSharp.Control.TaskSeq.Test/TaskSeq.Concat.Tests.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ module SideEffect =
249249
let mutable i = 0
250250

251251
taskSeq {
252-
yield ResizeArray { 1..10 }
253-
yield ResizeArray { 1..10 }
252+
yield ResizeArray [ 1..10 ]
253+
yield ResizeArray [ 1..10 ]
254254

255255
yield
256256
ResizeArray(

src/FSharp.Control.TaskSeq/TaskSeqInternal.fs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ module internal TaskSeqInternal =
277277

278278
let init count initializer = taskSeq {
279279
let mutable i = 0
280-
let mutable value: Lazy<'T> = Unchecked.defaultof<_>
281280

282281
let count =
283282
match count with
@@ -290,28 +289,13 @@ module internal TaskSeqInternal =
290289
match initializer with
291290
| InitAction init ->
292291
while i < count do
293-
// using Lazy gives us locking and safe multiple access to the cached value, if
294-
// multiple threads access the same item through the same enumerator (which is
295-
// bad practice, but hey, who're we to judge).
296-
if isNull value then
297-
value <- Lazy<_>.Create(fun () -> init i)
298-
299-
yield value.Force()
300-
value <- Unchecked.defaultof<_>
292+
yield init i
301293
i <- i + 1
302294

303295
| InitActionAsync asyncInit ->
304296
while i < count do
305-
// using Lazy gives us locking and safe multiple access to the cached value, if
306-
// multiple threads access the same item through the same enumerator (which is
307-
// bad practice, but hey, who're we to judge).
308-
if isNull value then
309-
// TODO: is there a 'Lazy' we can use with Task?
310-
let! value' = asyncInit i
311-
value <- Lazy<_>.CreateFromValue value'
312-
313-
yield value.Force()
314-
value <- Unchecked.defaultof<_>
297+
let! result = asyncInit i
298+
yield result
315299
i <- i + 1
316300

317301
}

0 commit comments

Comments
 (0)