-
Notifications
You must be signed in to change notification settings - Fork 321
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
proc_maps: Parse address and device without allocating #572
Merged
SuperQ
merged 2 commits into
prometheus:master
from
javierhonduco:optimise-maps-device-and-address-parsing
Sep 22, 2023
Merged
proc_maps: Parse address and device without allocating #572
SuperQ
merged 2 commits into
prometheus:master
from
javierhonduco:optimise-maps-device-and-address-parsing
Sep 22, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kakkoyun
approved these changes
Sep 19, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🥇
In our project we need to parse proc maps pretty frequently and we've noticed that there are lots of small allocations coming from parsing the device and addresses from procfs' maps file. The rough split of memory allocated is: - bufio.(*Scanner).Text: 25% - strings.Split: 50% - string.Fields: 25% The two callers of strings.Split are the two parsing functions that we are optimising here. I've added some benchmarks to show the improvements. Before ====== ``` $ go test -benchmem -run=^$ -bench ^BenchmarkParse.*$ github.com/prometheus/procfs goos: linux goarch: amd64 pkg: github.com/prometheus/procfs cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz BenchmarkParseAddress-12 12218004 123.0 ns/op 32 B/op 1 allocs/op BenchmarkParseDevice-12 15074881 85.11 ns/op 32 B/op 1 allocs/op PASS ok github.com/prometheus/procfs 2.978s ``` After ===== ``` $ go test -benchmem -run=^$ -bench ^BenchmarkParse.*$ github.com/prometheus/procfs goos: linux goarch: amd64 pkg: github.com/prometheus/procfs cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz BenchmarkParseAddress-12 28619314 50.45 ns/op 0 B/op 0 allocs/op BenchmarkParseDevice-12 49721935 29.66 ns/op 0 B/op 0 allocs/op PASS ok github.com/prometheus/procfs 2.991s ``` Signed-off-by: Francisco Javier Honduvilla Coto <[email protected]>
SuperQ
approved these changes
Sep 22, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice.
jritter
pushed a commit
to jritter/procfs
that referenced
this pull request
Jul 15, 2024
In our project we need to parse proc maps pretty frequently and we've noticed that there are lots of small allocations coming from parsing the device and addresses from procfs' maps file. The rough split of memory allocated is: - bufio.(*Scanner).Text: 25% - strings.Split: 50% - string.Fields: 25% The two callers of strings.Split are the two parsing functions that we are optimising here. I've added some benchmarks to show the improvements. Before ====== ``` $ go test -benchmem -run=^$ -bench ^BenchmarkParse.*$ github.com/prometheus/procfs goos: linux goarch: amd64 pkg: github.com/prometheus/procfs cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz BenchmarkParseAddress-12 12218004 123.0 ns/op 32 B/op 1 allocs/op BenchmarkParseDevice-12 15074881 85.11 ns/op 32 B/op 1 allocs/op PASS ok github.com/prometheus/procfs 2.978s ``` After ===== ``` $ go test -benchmem -run=^$ -bench ^BenchmarkParse.*$ github.com/prometheus/procfs goos: linux goarch: amd64 pkg: github.com/prometheus/procfs cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz BenchmarkParseAddress-12 28619314 50.45 ns/op 0 B/op 0 allocs/op BenchmarkParseDevice-12 49721935 29.66 ns/op 0 B/op 0 allocs/op PASS ok github.com/prometheus/procfs 2.991s ``` Signed-off-by: Francisco Javier Honduvilla Coto <[email protected]> Co-authored-by: Ben Kochie <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In our project we need to parse proc maps pretty frequently and we've noticed that there are lots of small allocations coming from parsing the device and addresses from procfs' maps file.
The rough split of memory allocated is:
The two callers of strings.Split are the two parsing functions that we are optimising here. I've added some benchmarks to show the improvements.
Before
After