Skip to content
This repository was archived by the owner on Nov 13, 2025. It is now read-only.

feat(Performance): refactor send/receive improve performance#26

Merged
ArgoZhang merged 53 commits into
masterfrom
perf
Sep 16, 2025
Merged

feat(Performance): refactor send/receive improve performance#26
ArgoZhang merged 53 commits into
masterfrom
perf

Conversation

@ArgoZhang

Copy link
Copy Markdown
Member

Link issues

fixes #25

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Copilot AI review requested due to automatic review settings September 15, 2025 10:11

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.

Pull Request Overview

This pull request aims to improve the performance of TCP socket send/receive operations by refactoring the internal implementation. The key changes focus on simplifying the API and reducing memory allocations.

  • Removed logging infrastructure and dependency injection complexity
  • Simplified ReceiveAsync API to use buffer-based approach instead of returning Memory<byte>
  • Streamlined internal Sender and Receiver classes by removing memory pooling and pinning overhead

Reviewed Changes

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

Show a summary per file
File Description
UnitTestTcpSocket.csproj Added Microsoft.Extensions.DependencyInjection package dependency
TcpSocketFactoryTest.cs Updated test API calls to match new buffer-based ReceiveAsync, commented out many tests
SocketClientProviderTest.cs Updated test to use new buffer-based ReceiveAsync API
TcpSocketClientOptions.cs Removed logging options and changed NoDelay default
Longbow.TcpSocket.csproj Updated version, removed logging dependencies, pinned Longbow.Sockets version
Sender.cs Simplified by removing memory pinning and state management
Receiver.cs Removed array pooling and simplified buffer handling
ITcpSocketClient.cs Changed ReceiveAsync signature to buffer-based approach
DefaultTcpSocketClient.cs Major refactor removing DI, logging, and reconnection logic
Service extensions Updated to use Options pattern and simplified registration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


<ItemGroup>
<PackageReference Include="Longbow.Sockets" Version="9.*" />
<PackageReference Include="Longbow.Sockets" Version="9.0.2" />

Copilot AI Sep 15, 2025

Copy link

Choose a reason for hiding this comment

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

The version is now pinned to a specific version (9.0.2) instead of the previous wildcard pattern (9.*). This removes flexibility for patch updates and may require manual updates for bug fixes in the dependency.

Suggested change
<PackageReference Include="Longbow.Sockets" Version="9.0.2" />
<PackageReference Include="Longbow.Sockets" Version="9.0.*" />

Copilot uses AI. Check for mistakes.
if (e.SocketError == SocketError.Success)
{
tcs.TrySetResult();
tcs.TrySetResult(true);

Copilot AI Sep 15, 2025

Copy link

Choose a reason for hiding this comment

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

The method now returns true for successful sends, but the return type changed from ValueTask to ValueTask<bool>. However, there's no handling for partial sends - if SendAsync only sends part of the data, this will still return true even though not all data was sent.

Suggested change
tcs.TrySetResult(true);
// Check for partial send
if (e.BytesTransferred == e.Count)
{
tcs.TrySetResult(true);
}
else
{
// Partial send: not all data was sent
tcs.TrySetResult(false);
}

Copilot uses AI. Check for mistakes.
}

_args.UserToken = (state, registration);
_args.SetBuffer(buffer);

Copilot AI Sep 15, 2025

Copy link

Choose a reason for hiding this comment

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

The receiver now directly uses the provided buffer instead of using array pooling. This could lead to performance issues if the caller provides a very large buffer for small receives, as the entire buffer is set on the SocketAsyncEventArgs instead of using an appropriately-sized pooled buffer.

Copilot uses AI. Check for mistakes.
await _socketProvider.CloseAsync();
}
}
public ValueTask<int> ReceiveAsync(Memory<byte> buffer, CancellationToken token = default) => ReceiveCoreAsync(buffer, token);

Copilot AI Sep 15, 2025

Copy link

Choose a reason for hiding this comment

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

The public ReceiveAsync method doesn't validate if auto-receive is enabled. The removed validation that threw InvalidOperationException when IsAutoReceive is true means users could now incorrectly call both manual and automatic receive simultaneously, leading to undefined behavior.

Copilot uses AI. Check for mistakes.
@ArgoZhang ArgoZhang merged commit f5ee572 into master Sep 16, 2025
0 of 3 checks passed
@ArgoZhang ArgoZhang deleted the perf branch September 16, 2025 08:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(Performance): refactor send/receive improve performance

2 participants