-
Notifications
You must be signed in to change notification settings - Fork 581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
7.0 Proposal: BasicPublish with ROM<byte> for exchange and routing key #972
Comments
I'm all for performance, but I don't really see this as something that will be widely used, but for some very niche cases. IO will always be the bottleneck, not CPU usage. |
I've just had a second thought about this, and I've gone 180 on my original comment. I think this might be a clever idea for high-perf scenarios. I also remembered that there exists an API that does similar things: https://github.com/StackExchange/StackExchange.Redis/blob/main/src/StackExchange.Redis/Interfaces/IDatabase.cs#L241 The StackExchange.Redis API uses RedisKey structs as key parameters which have implicit conversion to both byte[] and string: https://github.com/StackExchange/StackExchange.Redis/blob/main/src/StackExchange.Redis/RedisKey.cs#L178-L191 That means that clients that use hardcoded strings for exchanges/queues etc. can define a ready-made |
To indicate the caching intent for this, we could also define the signature as public readonly struct RabbitMqString
{
public readonly string Value;
internal readonly ReadOnlyMemory<byte> CachedBytes;
public RabbitMqString(string value) { /* implement */ };
}
/**************** OR *****************/
public sealed class RabbitMqString
{
private ReadOnlyMemory<byte> _cache;
public string Value { get;}
internal ReadOnlyMemory<byte> CachedBytes => /* populate _cache if not empty or return _cache */;
public RabbitMqString(string value) { /* implement */ };
} where the struct would build the cache within the ctor, while the class could defer it to it's first use if we want to. |
Update from a local running version on this:
Obviously the gain increases the larger the string (Exchange / RoutingKey) is. (Benchmark is with "Exchange_OR_RoutingKey"). Another benchmark to serialize into the 3 frames of a message:
It my does not seem huge, but it increases the throughput on the most relevant hotpath. |
The basic publish is one of the "hottest" method we have, so any improvements there are surely very valuable.
Extracted from #970, I propose to extend the IModel interface with a new method for 7.0:
void BasicPublish(ReadOnlyMemory<byte> exchange, ReadOnlyMemory<byte> routingKey, bool mandatory, IBasicProperties basicProperties, ReadOnlyMemory<byte> body);
This replaces the expensive string -> byte encoding for the often times same string.
The text was updated successfully, but these errors were encountered: