hashicorp / go-metrics

A Golang library for exporting performance and runtime metrics to external metrics systems (i.e. statsite, statsd)
MIT License
1.46k stars 177 forks source link

optimize allocations during label filtering #139

Closed cbosss closed 2 years ago

cbosss commented 2 years ago

This showed up in some pprof profiling of our application. We do not have any blocked/allowed labels configured, however the library was still creating a duplicate of the Label slice on each call. This caused unnecessary allocations.

This PR cleans up some unnecessary allocations in the following edge cases:

  1. An empty (non nil) label slice is passed in.
  2. Neither blocked or allowed lists are configured.
  3. No labels are allowed.

Didn't see any contributing guides. Let me know if anything needs to change to get this merged!

hashicorp-cla commented 2 years ago

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.