Skip to content

Commit 617a22e

Browse files
committed
Merge branch 'lukebakken/string-types-2' into stringallocations
2 parents d4e88ca + a1eef4c commit 617a22e

File tree

101 files changed

+1536
-1093
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1536
-1093
lines changed

projects/Benchmarks/ConsumerDispatching/AsyncBasicConsumerFake.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public AsyncBasicConsumerFake(ManualResetEventSlim autoResetEvent)
1818
_autoResetEvent = autoResetEvent;
1919
}
2020

21-
public Task HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, ReadOnlyMemory<byte> exchange, ReadOnlyMemory<byte> routingKey,
21+
public Task HandleBasicDeliver(ConsumerTag consumerTag, ulong deliveryTag, bool redelivered,
22+
ExchangeName exchange, RoutingKey routingKey,
2223
in ReadOnlyBasicProperties properties, ReadOnlyMemory<byte> body)
2324
{
2425
if (Interlocked.Increment(ref _current) == Count)
@@ -29,7 +30,8 @@ public Task HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redel
2930
return Task.CompletedTask;
3031
}
3132

32-
Task IBasicConsumer.HandleBasicDeliverAsync(string consumerTag, ulong deliveryTag, bool redelivered, ReadOnlyMemory<byte> exchange, ReadOnlyMemory<byte> routingKey,
33+
Task IBasicConsumer.HandleBasicDeliverAsync(ConsumerTag consumerTag, ulong deliveryTag, bool redelivered,
34+
ExchangeName exchange, RoutingKey routingKey,
3335
ReadOnlyBasicProperties properties, ReadOnlyMemory<byte> body)
3436
{
3537
if (Interlocked.Increment(ref _current) == Count)
@@ -40,11 +42,11 @@ Task IBasicConsumer.HandleBasicDeliverAsync(string consumerTag, ulong deliveryTa
4042
return Task.CompletedTask;
4143
}
4244

43-
public Task HandleBasicCancel(string consumerTag) => Task.CompletedTask;
45+
public Task HandleBasicCancel(ConsumerTag consumerTag) => Task.CompletedTask;
4446

45-
public Task HandleBasicCancelOk(string consumerTag) => Task.CompletedTask;
47+
public Task HandleBasicCancelOk(ConsumerTag consumerTag) => Task.CompletedTask;
4648

47-
public Task HandleBasicConsumeOk(string consumerTag) => Task.CompletedTask;
49+
public Task HandleBasicConsumeOk(ConsumerTag consumerTag) => Task.CompletedTask;
4850

4951
public Task HandleChannelShutdown(object channel, ShutdownEventArgs reason) => Task.CompletedTask;
5052

@@ -62,19 +64,19 @@ public event AsyncEventHandler<ConsumerEventArgs> ConsumerCancelled
6264
remove { }
6365
}
6466

65-
void IBasicConsumer.HandleBasicCancelOk(string consumerTag)
67+
void IBasicConsumer.HandleBasicCancelOk(ConsumerTag consumerTag)
6668
{
6769
}
6870

69-
void IBasicConsumer.HandleBasicConsumeOk(string consumerTag)
71+
void IBasicConsumer.HandleBasicConsumeOk(ConsumerTag consumerTag)
7072
{
7173
}
7274

7375
void IBasicConsumer.HandleChannelShutdown(object channel, ShutdownEventArgs reason)
7476
{
7577
}
7678

77-
void IBasicConsumer.HandleBasicCancel(string consumerTag)
79+
void IBasicConsumer.HandleBasicCancel(ConsumerTag consumerTag)
7880
{
7981
}
8082
}

projects/Benchmarks/ConsumerDispatching/ConsumerDispatcher.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Text;
32
using System.Threading;
43
using System.Threading.Tasks;
54
using BenchmarkDotNet.Attributes;
@@ -16,11 +15,12 @@ public class ConsumerDispatcherBase
1615

1716
private protected IConsumerDispatcher _dispatcher;
1817
private protected readonly AsyncBasicConsumerFake _consumer = new AsyncBasicConsumerFake(_autoResetEvent);
19-
protected readonly string _consumerTag = "ConsumerTag";
20-
protected static readonly byte[] _consumerTagBytes = Encoding.UTF8.GetBytes("ConsumerTag");
18+
19+
protected static readonly ConsumerTag _consumerTag = new ConsumerTag("ConsumerTag");
20+
protected static readonly ExchangeName _exchange = new ExchangeName("Exchange");
21+
protected static readonly RoutingKey _routingKey = new RoutingKey("RoutingKey");
22+
2123
protected readonly ulong _deliveryTag = 500UL;
22-
protected static readonly byte[] _exchange = Encoding.UTF8.GetBytes("Exchange");
23-
protected static readonly byte[] _routingKey = Encoding.UTF8.GetBytes("RoutingKey");
2424
protected readonly ReadOnlyBasicProperties _properties = new ReadOnlyBasicProperties();
2525
protected readonly byte[] _method = new byte[512];
2626
protected readonly byte[] _body = new byte[512];
@@ -51,12 +51,15 @@ public async Task SetUpAsyncConsumer()
5151
[Benchmark]
5252
public async Task AsyncConsumerDispatcher()
5353
{
54+
var m = new MethodBasicDeliver();
55+
m.SetUp();
56+
using (RentedMemory method = new RentedMemory(m.Buffer.ToArray()))
5457
using (RentedMemory body = new RentedMemory(_body))
5558
{
5659
for (int i = 0; i < Count; i++)
5760
{
58-
await _dispatcher.HandleBasicDeliverAsync(_consumerTagBytes, _deliveryTag,
59-
false, _exchange, _routingKey, _properties, body, CancellationToken.None);
61+
await _dispatcher.HandleBasicDeliverAsync(_deliveryTag,
62+
false, _properties, method, body, CancellationToken.None);
6063
}
6164
_autoResetEvent.Wait();
6265
_autoResetEvent.Reset();
@@ -74,12 +77,15 @@ public async Task SetUpConsumer()
7477
[Benchmark]
7578
public async Task ConsumerDispatcher()
7679
{
80+
var m = new MethodBasicDeliver();
81+
m.SetUp();
82+
using (RentedMemory method = new RentedMemory(m.Buffer.ToArray()))
7783
using (RentedMemory body = new RentedMemory(_body))
7884
{
7985
for (int i = 0; i < Count; i++)
8086
{
81-
await _dispatcher.HandleBasicDeliverAsync(_consumerTagBytes, _deliveryTag,
82-
false, _exchange, _routingKey, _properties, body, CancellationToken.None);
87+
await _dispatcher.HandleBasicDeliverAsync(_deliveryTag,
88+
false, _properties, method, body, CancellationToken.None);
8389
}
8490
_autoResetEvent.Wait();
8591
_autoResetEvent.Reset();

projects/Benchmarks/Networking/Networking_BasicDeliver_Commons.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static async Task Publish_Hello_World(IConnection connection, uint messag
2828

2929
for (int i = 0; i < messageCount; i++)
3030
{
31-
await channel.BasicPublishAsync("", queue.QueueName, body);
31+
await channel.BasicPublishAsync(ExchangeName.Empty, queue.QueueName, body);
3232
}
3333

3434
await tcs.Task;

projects/Benchmarks/WireFormatting/MethodSerialization.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace RabbitMQ.Benchmarks
1111
[BenchmarkCategory("Methods")]
1212
public class MethodSerializationBase
1313
{
14-
protected readonly Memory<byte> _buffer = new byte[1024];
14+
public readonly Memory<byte> Buffer = new byte[1024];
1515

1616
[GlobalSetup]
1717
public virtual void SetUp() { }
@@ -20,13 +20,13 @@ public virtual void SetUp() { }
2020
public class MethodBasicAck : MethodSerializationBase
2121
{
2222
private readonly BasicAck _basicAck = new BasicAck(ulong.MaxValue, true);
23-
public override void SetUp() => _basicAck.WriteTo(_buffer.Span);
23+
public override void SetUp() => _basicAck.WriteTo(Buffer.Span);
2424

2525
[Benchmark]
26-
public ulong BasicAckRead() => new BasicAck(_buffer.Span)._deliveryTag; // return one property to not box when returning an object instead
26+
public ulong BasicAckRead() => new BasicAck(Buffer.Span)._deliveryTag; // return one property to not box when returning an object instead
2727

2828
[Benchmark]
29-
public int BasicAckWrite() => _basicAck.WriteTo(_buffer.Span);
29+
public int BasicAckWrite() => _basicAck.WriteTo(Buffer.Span);
3030
}
3131

3232
public class MethodBasicDeliver : MethodSerializationBase
@@ -37,21 +37,21 @@ public class MethodBasicDeliver : MethodSerializationBase
3737

3838
public override void SetUp()
3939
{
40-
int offset = Client.Impl.WireFormatting.WriteShortstr(ref _buffer.Span.GetStart(), string.Empty);
41-
offset += Client.Impl.WireFormatting.WriteLonglong(ref _buffer.Span.GetOffset(offset), 0);
42-
offset += Client.Impl.WireFormatting.WriteBits(ref _buffer.Span.GetOffset(offset), false);
43-
offset += Client.Impl.WireFormatting.WriteShortstr(ref _buffer.Span.GetOffset(offset), string.Empty);
44-
Client.Impl.WireFormatting.WriteShortstr(ref _buffer.Span.GetOffset(offset), string.Empty);
40+
int offset = Client.Impl.WireFormatting.WriteShortstr(ref Buffer.Span.GetStart(), string.Empty);
41+
offset += Client.Impl.WireFormatting.WriteLonglong(ref Buffer.Span.GetOffset(offset), 0);
42+
offset += Client.Impl.WireFormatting.WriteBits(ref Buffer.Span.GetOffset(offset), false);
43+
offset += Client.Impl.WireFormatting.WriteShortstr(ref Buffer.Span.GetOffset(offset), string.Empty);
44+
Client.Impl.WireFormatting.WriteShortstr(ref Buffer.Span.GetOffset(offset), string.Empty);
4545
}
4646

4747
[Benchmark]
48-
public object BasicDeliverRead() => new BasicDeliver(_buffer)._consumerTag; // return one property to not box when returning an object instead
48+
public object BasicDeliverRead() => new BasicDeliver(Buffer)._consumerTag; // return one property to not box when returning an object instead
4949

5050
[Benchmark]
51-
public int BasicPublishWrite() => _basicPublish.WriteTo(_buffer.Span);
51+
public int BasicPublishWrite() => _basicPublish.WriteTo(Buffer.Span);
5252

5353
[Benchmark]
54-
public int BasicPublishMemoryWrite() => _basicPublishMemory.WriteTo(_buffer.Span);
54+
public int BasicPublishMemoryWrite() => _basicPublishMemory.WriteTo(Buffer.Span);
5555

5656
[Benchmark]
5757
public int BasicPublishSize() => _basicPublish.GetRequiredBufferSize();
@@ -64,25 +64,25 @@ public class MethodChannelClose : MethodSerializationBase
6464
{
6565
private readonly ChannelClose _channelClose = new ChannelClose(333, string.Empty, 0099, 2999);
6666

67-
public override void SetUp() => _channelClose.WriteTo(_buffer.Span);
67+
public override void SetUp() => _channelClose.WriteTo(Buffer.Span);
6868

6969
[Benchmark]
70-
public object ChannelCloseRead() => new ChannelClose(_buffer.Span)._replyText; // return one property to not box when returning an object instead
70+
public object ChannelCloseRead() => new ChannelClose(Buffer.Span)._replyText; // return one property to not box when returning an object instead
7171

7272
[Benchmark]
73-
public int ChannelCloseWrite() => _channelClose.WriteTo(_buffer.Span);
73+
public int ChannelCloseWrite() => _channelClose.WriteTo(Buffer.Span);
7474
}
7575

7676
public class MethodBasicProperties : MethodSerializationBase
7777
{
7878
private readonly IAmqpWriteable _basicProperties = new BasicProperties { Persistent = true, AppId = "AppId", ContentEncoding = "content", };
79-
public override void SetUp() => _basicProperties.WriteTo(_buffer.Span);
79+
public override void SetUp() => _basicProperties.WriteTo(Buffer.Span);
8080

8181
[Benchmark]
82-
public ReadOnlyBasicProperties BasicPropertiesRead() => new ReadOnlyBasicProperties(_buffer.Span);
82+
public ReadOnlyBasicProperties BasicPropertiesRead() => new ReadOnlyBasicProperties(Buffer.Span);
8383

8484
[Benchmark]
85-
public int BasicPropertiesWrite() => _basicProperties.WriteTo(_buffer.Span);
85+
public int BasicPropertiesWrite() => _basicProperties.WriteTo(Buffer.Span);
8686

8787
[Benchmark]
8888
public int BasicDeliverSize() => _basicProperties.GetRequiredBufferSize();

0 commit comments

Comments
 (0)