             throw ProtoDecoder.Error.mapEntryWithoutValue(key: key)
         }
 
+        // Preallocate a few empty slots to avoid reallocations.
+        if dictionary.isEmpty && MemoryLayout<V>.size <= ProtoReader.collectionPreallocationMaxValueSize {
+            dictionary.reserveCapacity(ProtoReader.collectionPreallocationSlotCount)
+        }
+
         dictionary[unwrappedKey] = unwrappedValue
     }
 

    }

    // MARK: - Private Properties

    private let buffer: ReadBuffer


            // than reallocate each time we add a new item. We'll use an arbitrary
            // (small) guess, and make sure we don't do this for large message
            // structs to avoid allocating too much extra memory.
            if array.isEmpty && MemoryLayout<T>.size <= ProtoReader.collectionPreallocationMaxValueSize {
                array.reserveCapacity(ProtoReader.collectionPreallocationSlotCount)
            }

            // This is a single entry in a regular repeated field
