question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support missing for contextual deserializer/serializer

See original GitHub issue

Right now, the code directly hooks into the legacy .Serializer / .Deserializer, which provides access to the Func<T, byte[]> etc, however IMO this violates the API.

The primary API is now the contextual serializer, by which I mean:

  • Grpc.Core[.Api] always uses the contextual serializer (except for some tests)
  • the contextual serializer always works (it is emulated when initialized from the legacy API), where-as the legacy serializer does not; see Marshaller.cs 44-47
// gRPC only uses contextual serializer/deserializer internally, so emulating the legacy
// (de)serializer is not necessary.
this.serializer = (msg) => { throw new NotImplementedException(); };
this.deserializer = (payload) => { throw new NotImplementedException(); };

This has two significant problems:

  1. any custom framework that tries to use the contextual serializer will not work from grpc-dotnet
  2. any improvements made to the core implementation of Marshaller will not be automatically exposed

For context on 2, see this PR, which does an in-place upgrade on how regular protoc-style protobuf deserializes, using the contextual API to significantly reduce buffer allocations. If grpc-dotnet does not use the contextual API: it will not benefit if/when those changes get merged.

I am aware of https://github.com/grpc/grpc-dotnet/issues/30, but IMO there are two different things:

  • #30 is about making better use of these APIs in the future
  • this report is about a fundamental bug that breaks the API today

You can also probably infer from this that I’m keen on using the contextual API, and generally improving this space - presumably looking into a new writer API too.

So, I guess my main point here is: grpc-dotnet should not use the legacy API - it should switch to the contextual API. I can offer some help with that if it would be welcome.


As a caveat / disclosure thing: I will acknowledge the remark:

/// Note: experimental API that can change or be removed without any prior notice.

but… if the API surface changes, consumers need to update anyway. I don’t personally see this as a reason not to consume this API.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
JamesNKcommented, Jul 4, 2019

I have plans to remove almost all non-message allocations on the server. I don’t want to micro-optimize for the serialization context if code will be thrown away post 3.0.

1reaction
mgravellcommented, Jul 4, 2019

You and me have very different views on allocations 😃

Right now I’m on a treasure-hunt for avoidable allocations in the Grpc.Core/Grpc.Core.Api path (the latter of which you should benefit from indirectly); I would do the same for Grpc-Dotnet, but … it is kinda awkward to work with right now unless I keep separate machines/VMs for preview6 and preview7 - and even then, it isn’t the easiest build since the dependency-tree is fast-moving.

But in all seriousness; if you can avoid an alloc per call (without bending the code too far out of shape), IMO you should avoid that alloc per call; they add up surprisingly quickly, and can quickly swamp the necessary allocations (i.e. the actual data payloads); on a high-throughput server allocations and GC can quickly dominate, or at least make a server more expensive than it needs to be (which can mean in terms of overhead on a box, or actual hosting costs for cloud/hosted services), even if performance is still acceptable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nested exception is org.springframework.core.serializer. ...
I got this error in ui application. org.springframework.data.redis.serializer.SerializationException: Cannot deserialize; nested exception is ...
Read more >
ContextualSerializer
ContextualSerializer ... This class provides support for retrieving a serializer in runtime, instead of using the one precompiled by the serialization plugin.
Read more >
Serialization and Deserialization - WCF
The DataContractSerializer serializes strings containing control characters with a hexadecimal value below 20 as XML entities. This may cause a ...
Read more >
The Serializer Component (Symfony Docs)
The first parameter of the serialize() is the object to be serialized and the second is used to choose the proper encoder, in...
Read more >
Serialization customization in Orleans
Learn how to customize serialization in .NET Orleans.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found