Skip to content

Commit 908b5a2

Browse files
committed
Create Action upfront to reduce temporary Action allocations.
This reduces allocations in the "ManyRowsNewSync" scenario by 19%.
1 parent 801d977 commit 908b5a2

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

src/MySqlConnector/MySqlClient/CommandExecutors/TextCommandExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public virtual async Task<DbDataReader> ExecuteReaderAsync(string commandText, M
5151
CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken)
5252
{
5353
cancellationToken.ThrowIfCancellationRequested();
54-
using (cancellationToken.Register(m_command.Cancel))
54+
using (cancellationToken.Register(m_command.CancelAction))
5555
{
5656
m_command.Connection.Session.StartQuerying(m_command);
5757
m_command.LastInsertedId = -1;

src/MySqlConnector/MySqlClient/MySqlCommand.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public MySqlCommand(string commandText, MySqlConnection connection, MySqlTransac
3737
DbTransaction = transaction;
3838
m_parameterCollection = new MySqlParameterCollection();
3939
CommandType = CommandType.Text;
40+
CancelAction = Cancel;
4041
}
4142

4243
public new MySqlParameterCollection Parameters
@@ -50,6 +51,8 @@ public MySqlCommand(string commandText, MySqlConnection connection, MySqlTransac
5051

5152
public override void Cancel() => Connection.Cancel(this);
5253

54+
internal Action CancelAction { get; private set; }
55+
5356
public override int ExecuteNonQuery() =>
5457
ExecuteNonQueryAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
5558

src/MySqlConnector/MySqlClient/MySqlDataReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private ValueTask<ResultSet> ScanResultSetAsync(IOBehavior ioBehavior, ResultSet
108108

109109
private async Task<ResultSet> ScanResultSetAsyncAwaited(IOBehavior ioBehavior, ResultSet resultSet, CancellationToken cancellationToken)
110110
{
111-
using (cancellationToken.Register(Command.Cancel))
111+
using (cancellationToken.Register(Command.CancelAction))
112112
{
113113
try
114114
{

src/MySqlConnector/MySqlClient/Results/ResultSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private ValueTask<Row> ScanRowAsync(IOBehavior ioBehavior, Row row, Cancellation
162162
if (BufferState == ResultSetState.HasMoreData || BufferState == ResultSetState.NoMoreData || BufferState == ResultSetState.None)
163163
return new ValueTask<Row>((Row)null);
164164

165-
using (cancellationToken.Register(Command.Cancel))
165+
using (cancellationToken.Register(Command.CancelAction))
166166
{
167167
var payloadValueTask = Session.ReceiveReplyAsync(ioBehavior, CancellationToken.None);
168168
return payloadValueTask.IsCompletedSuccessfully

0 commit comments

Comments
 (0)