perf: Optimize discovery.relabel by using label builder #2610
+79
−15
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 avoids building labels unnecessarily and uses a retained
LabelBuilder
for relabelling itself.Both cpu and allocations are reduced significantly:
Also in a real world deployment this is fairly impactful, both garbage collection and relabel use less cpu:
https://dev.grafana-dev.net/a/grafana-pyroscope-app/profiles-explorer?searchText=&panelType=time-series&layout=grid&hideNoData=off&explorationType=diff-flame-graph&var-serviceName=pyroscope-scrape-dev-001%2Falloy&var-profileMetricId=process_cpu:cpu:nanoseconds:cpu:nanoseconds&var-dataSource=edqsc0bzmfvnkc&var-filters=&var-filtersBaseline=&var-filtersComparison=&var-groupBy=&maxNodes=16384&from=now-30m&to=now&diffFrom=2025-02-04T14:30:26.865Z&diffTo=2025-02-04T14:45:22.388Z&diffFrom-2=2025-02-04T16:30:17.910Z&diffTo-2=2025-02-04T16:44:55.522Z&from-3=2025-02-04T14:00:00.000Z&to-3=2025-02-04T17:00:00.000Z&from-2=2025-02-04T14:00:00.000Z&to-2=2025-02-04T17:00:00.000Z
In terms of allocation bytes they are down by about 46%: