Priority: Major - P3
Affects Version/s: 1.0.3
Fix Version/s: None
Component/s: Wire Protocol
I was doing some performance tests of my app - in golang, using mongo-driver.
I've seen my app spent lots of time in decodeCommandOpMsg function.
After further investigation I've realized that decodeCommandOpMsg does decode full bson payload (all the way down) just to merge wiremessage sections toghether and return back as binary data (mainDoc.UnmarshalBSON and then mainDoc.MarshalBSON back again).
My theory is that it doesn't need to bother about internal structure of a document whatsoever - just merge top-level fields.
I've written simple benchmark and it seems it can be speeded up by the order of magnitude.
You can see benchmarks code here: https://github.com/g2a-com/mongo-go-driver/commit/1cf2b874b5f8dd022c2b7aed7e9090256eb335d8?diff=unified
And a proof of concept of the improvement here: https://github.com/g2a-com/mongo-go-driver/commit/deeacb2e7aa5e9cd7820c52b4f945fdc5d09be52
Results - without a change:
Results - without my change (https://github.com/g2a-com/mongo-go-driver/commit/deeacb2e7aa5e9cd7820c52b4f945fdc5d09be52):
Fun fact is that without my change in most cases documents returned from mongodb would be unmarshaled twice - once in decodeCommandOpMsg and 2nd time when driver's user wants to read his data (e.g. by cursor.Unmarshal).