Skip to content

[repo-assist] perf: avoid intermediate array allocation in toStrArray helpers - #488

Merged
sergey-tihon merged 1 commit into
masterfrom
repo-assist/perf-toStrArray-alloc-5af0f2fe495ea2cd
Sep 5, 2026
Merged

sergey-tihon merged 1 commit into
masterfrom
repo-assist/perf-toStrArray-alloc-5af0f2fe495ea2cd

Conversation

@github-actions

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

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

What

Replaces Array.map |> Array.toList with a single backward loop that builds the (name, str) list directly in toStrArray, toStrArrayDateTime, and toStrArrayDateTimeOffset in RuntimeHelpers.fs.

Why

These helpers are called once per array-typed query/path/header parameter on the request-serialization hot path (toQueryParams/toParam). The previous implementation allocated an intermediate array via Array.map before converting it to a list via Array.toList (a second full traversal + list allocation). The new version does a single reverse-order pass over the source array, consing directly onto an F# list, eliminating the intermediate array allocation and the extra traversal, while preserving the original element order.

Trade-offs

None functionally — output order and values are identical. Slightly more verbose code (explicit loop vs. pipeline) in exchange for one fewer allocation per call.

Test Status

  • Build: dotnet build tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj -c Release succeeded.
  • Unit tests: 548 passed, 1 skipped (pre-existing, unrelated), 0 failed.
  • Integration/provider tests: not run — pre-existing build failures in SwaggerProvider.ProviderTests unrelated to this change (verified reproduces identically on master without this change).

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • petstore.swagger.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "petstore.swagger.io"

See Network Configuration for more information.

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

Replace Array.map |> Array.toList with a single backward loop building
the (name, str) list directly. This runs once per array-typed
query/path/header parameter on the request-serialization hot path,
avoiding the temporary array allocated by Array.map before conversion
to a list.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sergey-tihon
sergey-tihon marked this pull request as ready for review September 5, 2026 15:10
Copilot AI lite review requested due to automatic review settings September 5, 2026 15:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is localized and preserves output order/behavior while reducing allocations in a well-scoped runtime helper.

Pull request overview

This PR optimizes request-serialization helpers in SwaggerProvider.Runtime by removing an intermediate array allocation when converting array-typed parameters into (name, value) lists for query/path/header serialization.

Changes:

  • Replaced Array.map |> Array.toList with a single reverse-index loop that conses directly into an F# list for toStrArray, toStrArrayDateTime, and toStrArrayDateTimeOffset.
  • Preserved original element ordering by iterating from Length - 1 down to 0.
File summaries
File Description
src/SwaggerProvider.Runtime/RuntimeHelpers.fs Reworks array-to-(name, string) conversion helpers to avoid intermediate array allocation on the hot path.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@sergey-tihon
sergey-tihon merged commit 921a233 into master Sep 5, 2026
10 checks passed
@sergey-tihon
sergey-tihon deleted the repo-assist/perf-toStrArray-alloc-5af0f2fe495ea2cd branch September 5, 2026 15:13
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.

2 participants