Skip to content

Prefer span slices over substrings in the F# instructions - #20642

Open
xperiandri wants to merge 3 commits into
dotnet:mainfrom
xperiandri:docs/span-slices-instruction
Open

xperiandri wants to merge 3 commits into
dotnet:mainfrom
xperiandri:docs/span-slices-instruction

Conversation

@xperiandri

Copy link
Copy Markdown
Contributor

A string slice that is only inspected (compared, trimmed, scanned, matched against a prefix) should be a ReadOnlySpan<char>, not a Substring or ToString() that copies it on every call. Only the value that leaves the function or is stored gets materialised, and a slice that outlives the stack frame is a ReadOnlyMemory<char>. src/Compiler references System.Memory on netstandard2.0, so the API is available everywhere the rule applies.

🤖 Generated with Claude Code

A string slice that is only inspected is a `ReadOnlySpan<char>`; a
`Substring` or `ToString()` copies it on every call. Materialise only
the value that leaves the function or is stored, and use
`ReadOnlyMemory<char>` for a slice that outlives the stack frame.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 26, 2026 14:02
@xperiandri
xperiandri requested a review from a team as a code owner September 26, 2026 14:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Address the identified guidance inconsistencies and System.Memory applicability issue.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

Updates F# guidance to prefer span-based string slicing and avoid unnecessary allocations.

Changes:

  • Recommends ReadOnlySpan<char> for temporary inspection.
  • Recommends ReadOnlyMemory<char> for stored or long-lived slices.
  • Adds allocation-free comparison examples.
File Summary
.github/​instructions/​FSharp.instructions.md Adds span and memory slicing guidance; requires corrections for package availability, span lifetimes, and comparison consistency.

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

Comment thread .github/instructions/FSharp.instructions.md Outdated
@github-actions github-actions Bot added the ⚠️ Affects-Agent-Config Tooling check: PR modifies AI agent instructions or workflows label Sep 26, 2026
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Tooling Safety Check — Affects-Agent-Config
Affects-Agent-Config: Agent instruction file changes repository guidance.

Generated by PR Tooling Safety Check · gpt56 685K · ◷

xperiandri and others added 2 commits September 26, 2026 20:30
The rule above asks for one on every `StartsWith`, and the span examples have none,
which reads as a contradiction rather than what it is: the span overloads that take no
comparison compare the characters, so they are ordinal already, while the `string`
overloads default to the current culture.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
MemoryExtensions has StringComparison overloads for ReadOnlySpan<char> even on netstandard2.0, so spans need no exception from the rule; the overloads without one are the generic element-wise ones and only happen to be ordinal. The span Contains also covers the missing String.Contains overload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

⚠️ Affects-Agent-Config Tooling check: PR modifies AI agent instructions or workflows

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

2 participants