Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Test coverage: Added tests for previously-untested public API functions `AsyncSeq.tryFirst`, `AsyncSeq.firstOrDefault`, `AsyncSeq.zipWithParallel`, `AsyncSeq.combineLatestWithAsync`, and `AsyncSeq.toObservable`. No functional changes.
* Fixed Fable CI build: `Microsoft.Bcl.AsyncInterfaces` was pinned to a specific version (`10.0.7`) that was older than the version resolved transitively via `System.Threading.Channels`, causing a `NU1605` package downgrade error that made Fable's project cracker fail during `dotnet fable`. The reference now uses `Version="*"` (matching `System.Threading.Channels`) so both resolve consistently. (#334)
* Performance: Optimised `AsyncSeq.distinctUntilChangedWithAsync` (and thus `distinctUntilChangedWith` / `distinctUntilChanged`) to track the previous element with a `hasPrev` flag and a direct `mutable` field instead of wrapping it in a `'T option`. Previously each iteration heap-allocated a new `Some` box; the new implementation eliminates that allocation, matching the pattern already used by `pairwise`.

### 4.17.0

Expand Down
14 changes: 8 additions & 6 deletions src/FSharp.Control.AsyncSeq/AsyncSeq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2740,16 +2740,18 @@ module AsyncSeq =
use ie = source.GetEnumerator()
let! move = ie.MoveNext()
let mutable b = move
let mutable prev = None
// Use a flag + mutable field instead of Option to avoid per-element heap allocation
let mutable hasPrev = false
let mutable prev = Unchecked.defaultof<'T>
while b.IsSome do
let v = b.Value
match prev with
| None ->
if not hasPrev then
yield v
| Some p ->
let! changed = f p v
else
let! changed = f prev v
if not changed then yield v
prev <- Some v
hasPrev <- true
prev <- v
let! moven = ie.MoveNext()
b <- moven }

Expand Down