[breaking] Reduce allocations in LineToEvents
by returning a single event instead of an slice
#577
Labels
enhancement
library
Issues pertaining to the use of the packages as a library more than the exporter itself
Description
The current implementation of the
LineToEvents
method inpkg/line/line.go
returns multiple events, which results in a lot of allocations in the statsd-exporter. We propose changing this method to return a single event instead.On the same refactoring step, we should introduce a "exploder" or "sampling" layer (or helper method on the event) which will keep the same behavior as we have now.
This is a breaking change on purpose which will force client projects using this repository as a library, to adapt to the new method signature.
Here is an example profile with samples using sampling rate, where you can see it takes more than 21% of total memory used:
![image](https://private-user-images.githubusercontent.com/2609731/367055292-c2c4de73-a148-461b-a759-d7bd5739ac53.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMTcyNjAsIm5iZiI6MTczOTIxNjk2MCwicGF0aCI6Ii8yNjA5NzMxLzM2NzA1NTI5Mi1jMmM0ZGU3My1hMTQ4LTQ2MWItYTc1OS1kN2JkNTczOWFjNTMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTBUMTk0OTIwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzE4ZWMxZDJlZDIwNDA3NDU4MWEyMjc5NmE2ODJjMDRkMGRjNjhkMDU0YTBlYjVjN2FmMWI0ZTUyOGVkNzNiZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.kCkxYTa10JMzdFzYNZonDZPVy8K-rPpMZQw2UUlrtGE)
Goals
Count
orSamplingRate
to another layer of the exporter.Proposed Solution
LineToEvents
method to return a single event.Count
orSamplingRate
in the event structure.Count
orSamplingRate
.Repro script
The text was updated successfully, but these errors were encountered: