Skip to content
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

ptypes: UnmarshalAny is slow #282

Closed
rogeralsing opened this issue Jan 25, 2017 · 3 comments
Closed

ptypes: UnmarshalAny is slow #282

rogeralsing opened this issue Jan 25, 2017 · 3 comments

Comments

@rogeralsing
Copy link

As discussed here:
gogo/protobuf#255 (comment)

We pass "dynamic" messages between nodes in Proto.Actor.
We have tried doing this using the Any type.
Which resulted in a huge perf drop.
from 1.85 mil msg/sec to 1.1 mil msg/sec, I suspect this is simply due to longer TypeURI's and more data to allocate.

The ptypes.UnmarshallAny however also rely on reflection to create the inner .Message value.
return reflect.New(t.Elem()).Interface().(proto.Message), nil

We did a spike, where we replaced this with a map[string] func() proto.Message.
So instead of using reflection, we simply resolve the factory func from the proto typename.
where each factory func itself would be something like func () { return &messages.MyMessage{} }

This moved us from our original 1.85 mil msg/sec to 2+ mil msg/sec.
So roughly 10% increase, this is for a full roundtrip. so only measuring deserialization in isolation would yiled a much higher increase.

This would be fairly easy to generate in the generated proto->go files.
You already register typenames and types.

Is this out of scope or something that could be of interest?

@bcmills
Copy link
Contributor

bcmills commented Jan 25, 2017

How many CPUs is your program running on, and have you profiled the source of the slowness?

We noticed significant lock contention in reflect.ptrTo (golang/go#17973) which should hopefully be fixed in Go 1.9 (golang/go#18177). One that is addressed, there isn't any obvious reason why the reflect version should be a particular bottleneck.

@bcmills
Copy link
Contributor

bcmills commented Jul 24, 2017

Have you had a chance to test your benchmark with go1.9beta2? If so, do you still observe excessive slowness in UnmarshalAny?

@dsnet dsnet changed the title UnmarshallAny is needlessly slow ptypes: UnmarshalAny is slow Feb 14, 2018
@dsnet
Copy link
Member

dsnet commented Aug 18, 2018

Going to close this as it seems the bottle neck is not with the Go protobuf code, but rather with the reflect package. Since Go1.9, it could have been improved. Who knows?

@dsnet dsnet closed this as completed Aug 18, 2018
@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants