Optimize tag handling #14
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This optimizes how tags are handled to minimize map to slice conversions. One of the nice things about this library is that tags can be specified as a map instead of having to munge tag keys and values together as is necessary with datadog-go. However, the current version converts between map and list on every metric call which leads to a lot of extra allocations. The main reason for maintaining the map at all was to ensure duplicate tags got overwritten. However, I don't know of any use cases where this kind of override is currently being used. Secondly, I tested how DataDog would handle duplicate tag keys and found that it will report both:

Note: It shows the values comma separated but if I were to filter for just
testapp:abc
I would get both the yellow and purple lines.The savings are significant in memory and CPU time:
Note: This also adds back the dep files so that teams not on go mods will still be able to upgrade.