Skip to content

Avoid the intermediate array allocation in project OtherOptions - #20499

Open
xperiandri wants to merge 2 commits into
dotnet:mainfrom
xperiandri:optimize-otherOptions-array-append
Open

Avoid the intermediate array allocation in project OtherOptions#20499
xperiandri wants to merge 2 commits into
dotnet:mainfrom
xperiandri:optimize-otherOptions-array-append

Conversation

@xperiandri

Copy link
Copy Markdown
Contributor

Description

Split out of #20274 at T-Gro's request — the original rewrite there also silently reversed the -r: flag order, which this version does not.

FSharpProjectOptionsReactor.tryComputeOptionsBySingleScriptOrFile built the OtherOptions array for an F#-metadata project as:

project.ProjectReferences
|> Seq.map (fun x -> "-r:" + project.Solution.GetProject(x.ProjectId).OutputFilePath)
|> Array.ofSeq
|> Array.append (
    project.MetadataReferences.OfType<PortableExecutableReference>()
    |> Seq.map (fun x -> "-r:" + x.FilePath)
    |> Array.ofSeq
)

Two arrays are allocated (Array.ofSeq twice) and a third for the concatenation (Array.append). Replaced with a single array comprehension that yields both reference kinds directly, preserving the original element order (metadata references, then project references) so no consumer-visible behavior changes.

This runs once per non-open-document, non-script F# file whose project is compiled from a project-system snapshot, so the allocation count scales with reference count × such computations.

Checklist

  • Test cases added — mechanical allocation-only refactor, no behavior change to cover.
  • Performance benchmarks added in case of performance changes — not applicable; this is a straightforward allocation-count reduction (3 arrays → 1), not a hot-path change requiring a BDN benchmark.
  • Release notes entry updated: docs/release-notes/.VisualStudio/18.vNext.md (added in a follow-up commit once this PR's number was known).

🤖 Generated with Claude Code

Seq.map |> Array.ofSeq |> Array.append allocated two arrays and copied
into a third. Build the -r: flags in one array comprehension instead,
keeping the original metadata-references-then-project-references order.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

❗ Release notes required

You can open this PR in browser to add release notes: open in github.dev


✅ Found changes and release notes in following paths:

Change path Release notes path Description
`vsintegration/src` docs/release-notes/.VisualStudio/18.vNext.md

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@xperiandri xperiandri changed the title Avoid the intermediate array allocation in project OtherOptions Avoid the intermediate array allocation in project OtherOptions Sep 9, 2026
@github-actions github-actions Bot added the ⚠️ Affects-Design-Time Tooling check: PR touches type providers or dependency manager label Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🔍 Tooling Safety Check — Affects-Design-Time
Affects-Design-Time: Modifies IDE project-options code that runs during design time.

Generated by PR Tooling Safety Check · gpt56 487.6K ·

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

Labels

⚠️ Affects-Design-Time Tooling check: PR touches type providers or dependency manager

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

1 participant