As part of SERVER-54664, the memory tracking for $group was refactored to get some code sharing with window functions. The new tracker uses a pattern such as this, which is inefficient since in the worst case it will need to access the map twice. Instead, we should use the returned result of try_emplace when updating the memory usage.