Skip to content

scraping: reduce memory allocations on Target labels#12084

Merged
bboreham merged 3 commits intoprometheus:mainfrom
bboreham:target-labels
Mar 22, 2023
Merged

scraping: reduce memory allocations on Target labels#12084
bboreham merged 3 commits intoprometheus:mainfrom
bboreham:target-labels

Conversation

@bboreham
Copy link
Member

@bboreham bboreham commented Mar 7, 2023

Adding Target.LabelsRange allows users of a Target to iterate labels without allocating heap memory.

Also, avoid copy of labels for dropped targets in scrapePool.Sync() - since the Target object was just created in this function, nobody else has a reference to it and there are no concerns about it being modified concurrently so we don't need to copy the value.

Includes a rewrite of resolveConflictingExposedLabels to use labels.Builder.Get, which simplifies it considerably.

Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice. But @roidelapluie should also have a look before merging.

This allows users of a Target to iterate labels without allocating heap memory.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Includes a rewrite of `resolveConflictingExposedLabels` to use
`labels.Builder.Get`, which simplifies it considerably.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Since the Target object was just created in this function, nobody else
has a reference to it and there are no concerns about it being modified
concurrently so we don't need to copy the value.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
@roidelapluie
Copy link
Member

Lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants