-
Notifications
You must be signed in to change notification settings - Fork 55
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
Support all binary payload APIs with only generics #143
Conversation
* Added switcher so we can add more benchmarks * Added a benchmark comparing pub wait-until-sent option
String serialized is causing excess allocations.
Performance considerations for publish: Without this change:
With this change:
|
This is to make the purpose of this method more obvious.
Complicates the API. Documentation should be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent! I really like how it simplifies the codebase.
Left one comment, but don't let that hold up merging this PR
|
||
await foreach (var msg in sub.Msgs.ReadAllAsync()) | ||
{ | ||
var data = Encoding.UTF8.GetString(msg.Data.ToArray()); | ||
var data = Encoding.UTF8.GetString(msg.Data!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the null-forgiving operator needed here? Is SubscribeAsync<T>
eventually returning T?
instead? Would be nice if we could avoid that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default values in general yield empty/sentinel payloads that's why there are T?
s in a lot of places. Do you think we shouldn't allow nulls? How would we handle sending and receiving empty payloads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, I guess there is no way to avoid it for reference types when default
may be retruned. Seeing as System.Text.JSON even does it
With this proposal we reduce the API footprint and make the default behaviour work as expected when sending byte types and strings:
The default serializer is smart enough to do the right thing handling known types avoiding surprises, especially when publishing.
The idea is to reduce the code duplication between generic calls and non-generic calls using binary data as payload and make the defaults work for the vast majority of the cases while having the flexibility of defining a custom serializer.
Related to #137