Description
runtime/pprof.Labels
is used in conjunction with runtime/pprof.WithLabels
to set pprof labels in a context for performance profiling.
Line 59 in c485506
Adding information for fine grained on demand profiling of already running binaries should idealy be very efficient so it can always stay enabled with minimal overhead. The current API could be made more efficient by requiring fewer heap allocations. Pprof information sourced from contexts added by census frameworks is used in large go deployments on every RPC request and thereby small performance gains add up to a larger resource saving across many servers.
The current runtime/pprof
API requires census frameworks such as OpenCensus to first convert their internal representation of key and value tag pairs (in a slice or map) to a slice of strings for input to runtime/pprof.Labels
.
This requires at least one heap allocation for a variable amount of labels. Then internaly the Labels
functions constructs a LabelSet
data structure which requires another allocation (the case where this uses more than one allocation will be improved with cl/181517 ). All in all this makes two heap allocations per context creation with pprof labels which can potentially be avoided.
I propose to extend runtime/pprof
to have an API that takes e.g. a mapping/iteration interface such that census frameworks can implement that interface on their internal tag representations (e.g. maps and slices with custom types) and runtime/pprof
can then source the labels to be set in a new runtime/pprof.WithLabels*
function without first requiring conversion between multiple internal and external data structures.
cl/188499 is a quick prototype as an example how this could look like. Different other ways of making an interface that can be used are possible to reduce allocations. Note that the LabelSet struct cant be changed to an interface itself (which seems the cleaner approach) due being not API backwards compatible.
Metadata
Metadata
Assignees
Type
Projects
Status