Skip to content

[repo-assist] Perf: eliminate per-element allocation in distinctUntilChangedWithAsync - #342

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/perf-distinctuntilchanged-20260901-1d3aaf225f407c6c
Draft

[repo-assist] Perf: eliminate per-element allocation in distinctUntilChangedWithAsync#342
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/perf-distinctuntilchanged-20260901-1d3aaf225f407c6c

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Optimises AsyncSeq.distinctUntilChangedWithAsync (and its callers distinctUntilChangedWith / distinctUntilChanged) to avoid a per-element heap allocation.

Previously the previous element was tracked as prev : 'T option, reassigned via prev <- Some v on every iteration — each call allocated a new Some box. The new implementation uses a hasPrev: bool flag plus a direct mutable prev: 'T field, matching the same optimisation already applied to pairwise in a prior PR (see AsyncSeq.fs pairwise for precedent).

No public API or behavioral changes — output sequence and semantics are identical for all inputs, including empty sequences and single-element sequences.

Test Status

  • dotnet build FSharp.Control.AsyncSeq.sln -c Release — succeeded, 0 errors.
  • dotnet test tests/FSharp.Control.AsyncSeq.Tests -c Release486/486 tests passed (no test changes needed; existing distinctUntilChanged/distinctUntilChangedWith tests continue to pass unchanged, confirming behavioral equivalence).

🤖 This PR was created by Repo Assist, an automated AI assistant, as part of scheduled performance-improvement maintenance (Task 8). A human maintainer should review before merging.

Generated by 🌈 Repo Assist, see workflow run. Learn more.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@ae8d551f07c7ed7619f8c58c7bb4c3ac89395d38

Track the previous element with a hasPrev flag and mutable field
instead of wrapping it in 'T option, matching the pattern already
used by pairwise. Removes a per-element heap allocation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants