Skip to content

[dotnet] [bidi] Optimize commands via ReadOnlyMemory#17205

Merged
nvborisenko merged 4 commits intoSeleniumHQ:trunkfrom
nvborisenko:bidi-optimize-send
Mar 11, 2026
Merged

[dotnet] [bidi] Optimize commands via ReadOnlyMemory#17205
nvborisenko merged 4 commits intoSeleniumHQ:trunkfrom
nvborisenko:bidi-optimize-send

Conversation

@nvborisenko
Copy link
Member

💥 What does this PR do?

This pull request updates the BiDi transport interface and its WebSocket implementation to improve performance and compatibility, especially for .NET 8 and later.

🔄 Types of changes

  • Cleanup (formatting, renaming)

Copilot AI review requested due to automatic review settings March 11, 2026 12:16
@qodo-code-review
Copy link
Contributor

Review Summary by Qodo

Optimize BiDi transport with ReadOnlyMemory and ValueTask

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Optimize BiDi transport by using ReadOnlyMemory<byte> instead of byte[]
• Replace Task with ValueTask for better async performance
• Add conditional compilation for .NET 8+ native support
• Maintain backward compatibility with earlier .NET versions

Grey Divider

File Changes

1. dotnet/src/webdriver/BiDi/ITransport.cs ✨ Enhancement +1/-1

Update SendAsync signature with ValueTask and ReadOnlyMemory

• Changed SendAsync method signature from Task to ValueTask
• Updated parameter type from byte[] to ReadOnlyMemory<byte>
• Improves performance by reducing allocations and enabling stack-based async operations

dotnet/src/webdriver/BiDi/ITransport.cs


2. dotnet/src/webdriver/BiDi/WebSocketTransport.cs ✨ Enhancement +17/-3

Implement ValueTask with platform-specific memory handling

• Implemented ValueTask return type in SendAsync method
• Added conditional compilation blocks for .NET 8+ and earlier versions
• For .NET 8+: directly pass ReadOnlyMemory<byte> to WebSocket API
• For earlier versions: convert to ArraySegment<byte> using MemoryMarshal.TryGetArray
• Updated logging to use data.Span for .NET 8+ compatibility

dotnet/src/webdriver/BiDi/WebSocketTransport.cs


Grey Divider

Qodo Logo

@selenium-ci selenium-ci added the C-dotnet .NET Bindings label Mar 11, 2026
@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Mar 11, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the .NET BiDi transport send path to use ReadOnlyMemory<byte>/ValueTask, enabling more efficient WebSocket sends on .NET 8+ while preserving compatibility on earlier targets.

Changes:

  • Change ITransport.SendAsync signature from Task/byte[] to ValueTask/ReadOnlyMemory<byte>.
  • Update WebSocketTransport.SendAsync to use the ClientWebSocket.SendAsync(ReadOnlyMemory<byte>, ...) overload on .NET 8+.
  • Add a NET<8 fallback that converts ReadOnlyMemory<byte> into an ArraySegment<byte> for ClientWebSocket.SendAsync(ArraySegment<byte>, ...).

Reviewed changes

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

File Description
dotnet/src/webdriver/BiDi/WebSocketTransport.cs Switch send API to ReadOnlyMemory<byte> with NET8 fast-path and NET<8 fallback.
dotnet/src/webdriver/BiDi/ITransport.cs Update transport interface send signature to ValueTask + ReadOnlyMemory<byte>.

Copilot AI review requested due to automatic review settings March 11, 2026 13:12
Copy link
Contributor

Copilot AI left a comment

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.

@nvborisenko nvborisenko merged commit 2feac4e into SeleniumHQ:trunk Mar 11, 2026
18 of 19 checks passed
@nvborisenko nvborisenko deleted the bidi-optimize-send branch March 11, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-dotnet .NET Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants