Commit c9f8844
perf: remove unnecessary Lazy allocation in TaskSeq.init per iteration
The `init` and `initInfinite` functions previously wrapped each yielded
value in a `Lazy<'T>` object on every iteration, then immediately discarded
it. This caused one heap allocation per element with no benefit:
- `Lazy<_>.Create(fun () -> init i)` allocates a Lazy + closure
- `value.Force()` goes through the Lazy lock-check machinery
- `value <- Unchecked.defaultof<_>` immediately nulls it out
The original rationale was thread safety for concurrent enumerator access,
but IAsyncEnumerator<T> explicitly does not support concurrent use, and
the pattern did not actually protect against all concurrent access bugs.
Replace with direct calls: `yield init i` and `let! result = asyncInit i; yield result`.
Also includes prerequisite fix: bare range expressions `{ 1..10 }` in
TaskSeq.Concat.Tests.fs replaced with list literals `[1..10]` to fix
FS3873 deprecation error on newer F# compilers (>= 9.x / .NET SDK 10.x).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 0fccf7b commit c9f8844
File tree
2 files changed
+5
-21
lines changed- src
- FSharp.Control.TaskSeq.Test
- FSharp.Control.TaskSeq
2 files changed
+5
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
253 | | - | |
| 252 | + | |
| 253 | + | |
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | | - | |
281 | 280 | | |
282 | 281 | | |
283 | 282 | | |
| |||
290 | 289 | | |
291 | 290 | | |
292 | 291 | | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
| 292 | + | |
301 | 293 | | |
302 | 294 | | |
303 | 295 | | |
304 | 296 | | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
| 297 | + | |
| 298 | + | |
315 | 299 | | |
316 | 300 | | |
317 | 301 | | |
| |||
0 commit comments