Skip to content

Avoid copying JSON input buffer before joining - #28224

Open
BigWorkk wants to merge 1 commit into
PowerShell:masterfrom
BigWorkk:perf/convertfromjson-no-array-copy
Open

BigWorkk wants to merge 1 commit into
PowerShell:masterfrom
BigWorkk:perf/convertfromjson-no-array-copy

Conversation

@BigWorkk

Copy link
Copy Markdown

Summary

Avoid materializing the buffered JSON input list as an intermediate array before joining multiline input. String.Join can consume the existing List<string> directly, preserving record order and the newline separator while removing one O(N) reference-array allocation.

Validation

  • Import-Module .\tools\ci.psm1 -Force; Start-PSBuild -NoPSModuleRestore
  • Start-PSPester -Path test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Json.Tests.ps1 -SkipTestToolBuild -ThrowOnFailure -Terse (84 passed)

No behavior changes are intended; the existing multiline-object tests cover the join path.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 17:35
@BigWorkk
BigWorkk requested a review from a team as a code owner October 16, 2026 17:35
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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 narrow optimization preserves join behavior, and existing multiline tests cover the affected path.

0 open findings

What changed in this PR

Removes an intermediate array allocation when joining buffered multiline input in ConvertFrom-Json.

Changes:

  • Passes the existing list directly to String.Join, preserving record order and newline separators.
File Description
src/​Microsoft.PowerShell.Commands.Utility/​commands/​utility/​WebCmdlet/​ConvertFromJsonCommand.cs Removes ToArray() from the buffered-input join.

🧠 Review effort: Balanced


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants