-
Notifications
You must be signed in to change notification settings - Fork 53
Add string version for SimpleMap methods #43
Comments
cc @odeke-em |
Note that only the If we don't care about backward-compatible, then we can just change the current methods signature, and also un-export |
The provided Lines 8 to 12 in 85c78b7
TL;DR: no, the Also, your new benchmark is highly synthetic as it uses the same key over and over. In practice, that won't be the case. Instead, every operation will use a different key. And each key being different means allocating a new slice each time, something that your benchmark omits. If you allocate a new (different) string each iteration, you'll probably see the benchmarks being much closer together. |
Hmm, my bad, as SimpleMap is only used for testing. |
Currently, all methods of SimpleMap get in a
[]byte
then convert it to string as key. This is ok for GET/DELETE operation, since when the compiler can optimize map lookup to not allocate new string instring([]byte)
conversion.For Set operation, which involve map assign, the
string([]byte)
conversion will allocate new string. If we instead do the conversion in the caller side, and pass in the string, the we can save allocation.I did a quick version:
For following benchmarks:
The result:
The text was updated successfully, but these errors were encountered: