Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Optimize discovery.relabel by using label builder #2610

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

simonswine
Copy link
Contributor

@simonswine simonswine commented Feb 4, 2025

This avoids building labels unnecessarily and uses a retained LabelBuilder for relabelling itself.

Both cpu and allocations are reduced significantly:

benchstat before.txt after-v2.txt
name        old time/op    new time/op    delta
Relabel-12    10.2ms ± 1%     9.6ms ± 1%   -5.29%  (p=0.000 n=9+9)

name        old alloc/op   new alloc/op   delta
Relabel-12    9.36MB ± 0%    5.15MB ± 0%  -44.91%  (p=0.000 n=10+10)

name        old allocs/op  new allocs/op  delta
Relabel-12      168k ± 0%      132k ± 0%  -21.66%  (p=0.000 n=10+9)

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

image

In terms of allocation bytes they are down by about 46%:

image

@simonswine simonswine force-pushed the 20250204_pref-optimize-discovery-relabel branch from c7da4aa to 35cc35d Compare February 4, 2025 17:27
This avoids building labels unneccessarily and uses a retained label
builder for relabeling itself.
@simonswine simonswine force-pushed the 20250204_pref-optimize-discovery-relabel branch from 35cc35d to 755bcfc Compare February 4, 2025 17:33
@simonswine
Copy link
Contributor Author

cc @marcsanmi your Benchmark lives on

@simonswine simonswine marked this pull request as ready for review February 4, 2025 17:47
@simonswine simonswine requested a review from a team as a code owner February 4, 2025 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant