Interesting observation! The most simple explanation would be that it is memory claimed by the Go runtime during parsing of the incoming bson from Mongo. You can try calling runtime.GC() 3 times after ingest and see if it changes your memory. Go does not free memory to the OS immediately, but this should do it.
2 other options, a bit more speculative:
Go maps have been known to have a bit of overhead in particular for small maps. Even when calling make() with the correct capacity. That doesn’t fit well with the memory profile you posted well, as I didn’t see any map container memory in there…
More probable might be that map keys are duplicated. So if you have 100 maps with the key “hello” you have 100 copies of the string “hello” in memory. Ideally all 100 maps qould share the same string instance. This often happens when parsing data from an incoming stream. You can either try to manually dedup the stringa, see if the mongo driver has the option, or use the new ‘unique’ package in Go 1.23
Must include CHANGELOG…
The changelog: