-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add Serialization.WithTransport overload that takes TState #4764
Add Serialization.WithTransport overload that takes TState #4764
Conversation
1f5031a
to
cf2691a
Compare
cf2691a
to
6a43275
Compare
var payloadType = e.Payload.GetType(); | ||
var serializer = Serialization.FindSerializerForType(payloadType, Configuration.DefaultSerializer); | ||
|
||
var serializer = Serialization.FindSerializerForType(e.Payload.GetType(), Configuration.DefaultSerializer); |
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.
Idea here is to avoid a local we don't use anywhere else.
|
||
// TODO: hack. Replace when https://github.com/akkadotnet/akka.net/issues/3811 | ||
string manifest = ""; | ||
var binary = Akka.Serialization.Serialization.WithTransport(Serialization.System, () => | ||
var (binary,manifest) = Akka.Serialization.Serialization.WithTransport(Serialization.System,(e.Payload,serializer) ,(state) => |
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.
by deconstructing here, we avoid requiring a capture on manifest
.
{ | ||
|
||
if (serializer is SerializerWithStringManifest stringManifest) | ||
var (thePayload, theSerializer) = state; | ||
string thisManifest = ""; |
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.
We're keeping a local here because changing this into a Ternary at end was both:
- Harder to read
- Slower because the complex ternary doesn't optimize well =/
It looks like in Sql.Common |
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.
LGTM - great idea
This PR adds the following method to Akka.Serialization.Serialization:
The purpose of this overload is to allow a TState value to be passed into the
action
when executed, allowing consumers to avoid allocations due to delegate captures if present.It looks like remoting already does something similar to this internally since it has access to the right internals, but there are other aspects of Akka (specifically persistence) that could benefit from this overload.
This PR also contains a benchmark of both versions of
WithTransport
. It looks like we are a little bit faster:I'm not sure why it comes up slower with
[MemoryDiagnoser]
, but important thing is we save ~90 bytes here:That may not look like much but since this is called deep in pipelines I'm expecting at least some gains in Persistence benches. Working on looking at that in Sql.Common