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

refactor(sumologicexporter): optimize fields stringification #517

Merged
merged 2 commits into from
Apr 4, 2022

Conversation

pmalek-sumo
Copy link
Contributor

Use byte slices instead of strings where possible and modify a "stringified field byte slice" in place to prevent unnecessary copies.

Additionally short circuit in fields.equals() when attribute maps have different length to prevent using cmp for comparison (which is relatively expensive).

$ go test -v -count 1 -run ^$ -bench BenchmarkFields -benchmem -count 1 . > old.txt
$ gco -
Previous HEAD position was 86d1d22 tests(sumologicexporter): add fields stringification benchmark
Switched to branch 'optimize-fields'
$ go test -v -count 1 -run ^$ -bench BenchmarkFields -benchmem -count 1 . > new.txt
$ benchcmp old.txt new.txt
benchcmp is deprecated in favor of benchstat: https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
benchmark              old ns/op     new ns/op     delta
BenchmarkFields-16     997           638           -35.97%

benchmark              old allocs     new allocs     delta
BenchmarkFields-16     17             11             -35.29%

benchmark              old bytes     new bytes     delta
BenchmarkFields-16     464           368           -20.69%

@pmalek-sumo pmalek-sumo self-assigned this Apr 4, 2022
@github-actions github-actions bot added the go label Apr 4, 2022
@pmalek-sumo pmalek-sumo marked this pull request as ready for review April 4, 2022 08:33
@pmalek-sumo pmalek-sumo requested a review from a team as a code owner April 4, 2022 08:33
@pmalek-sumo pmalek-sumo changed the title Optimize fields refactor(sumologicexporter): optimize fields stringification Apr 4, 2022
@pmalek-sumo pmalek-sumo merged commit b10cae0 into main Apr 4, 2022
@pmalek-sumo pmalek-sumo deleted the optimize-fields branch April 4, 2022 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants