Skip to content

Override IndentedTextWriter APIs that write spans.#130586

Open
teo-tsirpanis wants to merge 4 commits into
dotnet:mainfrom
teo-tsirpanis:indentedtextwriter-span-override
Open

Override IndentedTextWriter APIs that write spans.#130586
teo-tsirpanis wants to merge 4 commits into
dotnet:mainfrom
teo-tsirpanis:indentedtextwriter-span-override

Conversation

@teo-tsirpanis

Copy link
Copy Markdown
Contributor

Saves an array pool rent/return cycle and copying.

Saves an array pool rent/return cycle and copying.
Copilot AI review requested due to automatic review settings July 12, 2026 21:00
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jul 12, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

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.

Pull request overview

This PR updates System.CodeDom.Compiler.IndentedTextWriter to override the span-based TextWriter write APIs so span writes can be forwarded directly to the inner writer without the base TextWriter array-pool rent/copy path.

Changes:

  • Add IndentedTextWriter.Write(ReadOnlySpan<char>) and WriteLine(ReadOnlySpan<char>) overrides in CoreLib.
  • Add the corresponding members to the System.Runtime reference assembly for IndentedTextWriter.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/libraries/System.Private.CoreLib/src/System/CodeDom/Compiler/IndentedTextWriter.cs Adds span-based Write / WriteLine overrides to avoid the TextWriter pooling/copy path.
src/libraries/System.Runtime/ref/System.Runtime.cs Updates the public contract to include the new IndentedTextWriter override members.

public override void Write(char value) { }
public override void Write(char[]? buffer) { }
public override void Write(char[] buffer, int index, int count) { }
public override void Write(ReadOnlySpan<char> buffer) { }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think overriding a method needs approval.

Comment thread src/libraries/System.Runtime/ref/System.Runtime.cs Outdated
Comment thread src/libraries/System.Runtime/ref/System.Runtime.cs Outdated
Copilot AI review requested due to automatic review settings July 12, 2026 21:44

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Fixes race conditions if a synchronous operation is queued to run on another thread.
Copilot AI review requested due to automatic review settings July 12, 2026 22:03
@teo-tsirpanis
teo-tsirpanis force-pushed the indentedtextwriter-span-override branch from 8569c2b to 1f0b6d5 Compare July 12, 2026 22:03

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread src/libraries/System.Runtime/tests/System.IO.Tests/IndentedTextWriter.cs Outdated
Comment on lines 8123 to 8126
public override void Write(char[]? buffer) { }
public override void Write(char[] buffer, int index, int count) { }
public override void Write(System.ReadOnlySpan<char> buffer) { }
public override void Write(double value) { }
Comment on lines +139 to +143
public override void Write(ReadOnlySpan<char> buffer)
{
OutputTabs();
_writer.Write(buffer);
}
Copilot AI review requested due to automatic review settings July 12, 2026 23:46

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment on lines 8121 to 8126
@@ -8122,6 +8122,7 @@ public override void Write(bool value) { }
public override void Write(char value) { }
public override void Write(char[]? buffer) { }
public override void Write(char[] buffer, int index, int count) { }
public override void Write(System.ReadOnlySpan<char> buffer) { }
public override void Write(double value) { }
Comment on lines +139 to +143
public override void Write(ReadOnlySpan<char> buffer)
{
OutputTabs();
_writer.Write(buffer);
}
@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Workflow state for the Holistic Review Orchestrator.

{
  "version": 5,
  "last_dispatched_commit": "f13639544f05bb56cf6ebb63c910660ea8abf4e8",
  "last_dispatched_base_ref": "main",
  "last_dispatched_base_sha": "0e7b627c152a3c1885d1db498d81d01de55a3391",
  "last_reviewed_commit": "f13639544f05bb56cf6ebb63c910660ea8abf4e8",
  "last_reviewed_base_ref": "main",
  "last_reviewed_base_sha": "0e7b627c152a3c1885d1db498d81d01de55a3391",
  "last_recorded_worker_run_id": "29681936126",
  "review_attempt_commit": "",
  "review_attempt_base_ref": "",
  "review_attempt_count": 0,
  "max_review_attempts": 5,
  "review_history_format": "holistic-review-disclosure-v1",
  "review_history": [
    {
      "commit": "f13639544f05bb56cf6ebb63c910660ea8abf4e8",
      "review_id": 4730543703
    }
  ]
}

@github-actions github-actions Bot 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.

Holistic Review

Motivation: IndentedTextWriter derives from TextWriter but did not override the span-based Write(ReadOnlySpan<char>) and WriteLine(ReadOnlySpan<char>) methods. The inherited base implementations copy the span into a pooled char[] (an ArrayPool rent/return cycle plus a copy) before delegating. Since IndentedTextWriter wraps an inner TextWriter that natively supports spans, this indirection is pure overhead.

Approach: The PR adds the two missing overrides, each calling OutputTabs() and forwarding the span directly to the inner _writer, consistent with every other synchronous overload in the class. WriteLine(ReadOnlySpan<char>) also sets _tabsPending = true, matching the existing WriteLine pattern so subsequent writes are correctly re-indented. The reference assembly (System.Runtime.cs) is updated with the two new public overrides. Tests are extended: the parameterized Writes/WriteLines data sources gain span cases, the aggregate Writes_ProducesExpectedOutput test exercises both new APIs, and the test's TrackingTextWriter now overrides the span methods to assert delegation. The async test overrides were also refactored from manual Task result = ...; return result; to async/await, and the previously-tracked WriteAsync(string)/WriteLineAsync(string) overrides were joined by ReadOnlyMemory<char> overloads with new memory-based test cases.

Summary: This is a small, correct, and well-tested performance improvement. The new overrides faithfully mirror the surrounding synchronous patterns (tab output, delegation, and _tabsPending handling for WriteLine), the ref assembly is kept in sync, and the test coverage exercises both the indentation behavior and the delegation path. The async test refactor to async/await also fixes a latent correctness gap in the tracking writer where LastCalledMethod was previously set synchronously before the awaited operation completed and where the cancelable/ReadOnlyMemory overloads were not tracked. No functional or design concerns found. LGTM.

Note

This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.

Generated by Holistic Review · 42.1 AIC · ⌖ 10.4 AIC · ⊞ 10K

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

Labels

area-System.Runtime community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants