[Repo Assist] perf: direct loop in toResizeArrayAsync; simplify tryItem loop#381
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
Conversation
toResizeArrayAsync previously went through the iter function with a SimpleAction DU wrapper, causing a lambda closure allocation and discriminated-union wrapping on every call. The new direct loop eliminates these allocations and removes an extra layer of indirection. This benefits toArrayAsync, toListAsync, toResizeArrayAsync, and toIListAsync which all route through toResizeArrayAsync. tryItem previously used a while-loop with condition idx <= index and an inner if idx = index check on every iteration. The refactored version advances with idx < index and captures the current element after the loop, removing the redundant inner comparison from the hot path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist, an AI assistant.
Summary
Two small, focused performance improvements to
TaskSeqInternal.fs.1.
toResizeArrayAsync— direct loop instead ofiterBefore:
After:
Why it's faster: the old code created a lambda closure (
fun item -> res.Add item), wrapped it in aSimpleActiondiscriminated-union case (a heap allocation), then callediterwhich pattern-matched on the DU and drove a manualgo-flag loop. The new code does none of that.Scope:
toResizeArrayAsyncis the implementation shared bytoArrayAsync,toListAsync,toResizeArrayAsync, andtoIListAsync, so all four terminal operations benefit.2.
tryItem— remove redundant inner index checkBefore:
After:
Why it's faster: the old loop condition
idx <= indexmeant theif idx = indexbranch ran on every iteration (not just the last one). The refactored version moves the capture outside the loop, so there's no per-iteration inner comparison.Trade-offs
toResizeArrayAsyncchange also removes the dependency oniterfor this use-case, which improves code clarity.Test Status
✅ Build: 0 warnings, 0 errors (Release)
✅ Fantomas: formatting check passes
✅ Tests: 5093 passed, 2 skipped, 0 failed