-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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(logql): Micro-optimizations for IP filter #14072
Merged
Merged
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
Preallocate map to save 2 allocations. ``` goos: darwin goarch: arm64 pkg: github.com/grafana/loki/v3/pkg/logql/log cpu: Apple M2 Pro │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ _IPFilter/127.0.0.1-10 5.048µ ± 0% 4.591µ ± 1% -9.06% (p=0.002 n=6) _IPFilter/192.168.0.1-192.189.10.12-10 5.082µ ± 0% 4.634µ ± 0% -8.83% (p=0.002 n=6) _IPFilter/192.168.4.5/16-10 4.842µ ± 0% 4.390µ ± 0% -9.35% (p=0.002 n=6) geomean 4.990µ 4.537µ -9.08% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ _IPFilter/127.0.0.1-10 424.0 ± 0% 341.0 ± 0% -19.58% (p=0.002 n=6) _IPFilter/192.168.0.1-192.189.10.12-10 424.5 ± 0% 341.0 ± 0% -19.67% (p=0.002 n=6) _IPFilter/192.168.4.5/16-10 425.0 ± 0% 341.0 ± 0% -19.76% (p=0.002 n=6) geomean 424.5 341.0 -19.67% │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ _IPFilter/127.0.0.1-10 10.000 ± 0% 8.000 ± 0% -20.00% (p=0.002 n=6) _IPFilter/192.168.0.1-192.189.10.12-10 10.000 ± 0% 8.000 ± 0% -20.00% (p=0.002 n=6) _IPFilter/192.168.4.5/16-10 10.000 ± 0% 8.000 ± 0% -20.00% (p=0.002 n=6) geomean 10.00 8.000 -20.00% ```
Micro-optimization to use a struct instead of bool to save some bytes. ``` goos: darwin goarch: arm64 pkg: github.com/grafana/loki/v3/pkg/logql/log cpu: Apple M2 Pro │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ _IPFilter/127.0.0.1-10 4.595µ ± 1% 4.753µ ± 2% +3.44% (p=0.002 n=6) _IPFilter/192.168.0.1-192.189.10.12-10 4.611µ ± 1% 4.608µ ± 1% ~ (p=0.784 n=6) _IPFilter/192.168.4.5/16-10 4.374µ ± 0% 4.339µ ± 0% -0.81% (p=0.002 n=6) geomean 4.525µ 4.563µ +0.84% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ _IPFilter/127.0.0.1-10 341.0 ± 0% 272.0 ± 0% -20.23% (p=0.002 n=6) _IPFilter/192.168.0.1-192.189.10.12-10 341.0 ± 0% 272.0 ± 0% -20.23% (p=0.002 n=6) _IPFilter/192.168.4.5/16-10 341.0 ± 0% 272.0 ± 0% -20.23% (p=0.002 n=6) geomean 341.0 272.0 -20.23% │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ _IPFilter/127.0.0.1-10 8.000 ± 0% 8.000 ± 0% ~ (p=1.000 n=6) ¹ _IPFilter/192.168.0.1-192.189.10.12-10 8.000 ± 0% 8.000 ± 0% ~ (p=1.000 n=6) ¹ _IPFilter/192.168.4.5/16-10 8.000 ± 0% 8.000 ± 0% ~ (p=1.000 n=6) ¹ geomean 8.000 8.000 +0.00% ¹ all samples are equal ```
We can optimize even more here by eliminating the use of the map and opting to use a 256 len array instead for the lookup. ``` goos: darwin goarch: arm64 pkg: github.com/grafana/loki/v3/pkg/logql/log cpu: Apple M2 Pro │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ _IPFilter/127.0.0.1-10 4.609µ ± 1% 3.155µ ± 1% -31.55% (p=0.002 n=6) _IPFilter/192.168.0.1-192.189.10.12-10 4.621µ ± 2% 3.328µ ± 10% -27.98% (p=0.002 n=6) _IPFilter/192.168.4.5/16-10 4.388µ ± 2% 2.947µ ± 1% -32.84% (p=0.002 n=6) geomean 4.538µ 3.139µ -30.82% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ _IPFilter/127.0.0.1-10 272.00 ± 0% 32.00 ± 0% -88.24% (p=0.002 n=6) _IPFilter/192.168.0.1-192.189.10.12-10 272.00 ± 0% 32.00 ± 0% -88.24% (p=0.002 n=6) _IPFilter/192.168.4.5/16-10 272.00 ± 0% 32.00 ± 0% -88.24% (p=0.002 n=6) geomean 272.0 32.00 -88.24% │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ _IPFilter/127.0.0.1-10 8.000 ± 0% 3.000 ± 0% -62.50% (p=0.002 n=6) _IPFilter/192.168.0.1-192.189.10.12-10 8.000 ± 0% 3.000 ± 0% -62.50% (p=0.002 n=6) _IPFilter/192.168.4.5/16-10 8.000 ± 0% 3.000 ± 0% -62.50% (p=0.002 n=6) geomean 8.000 3.000 -62.50% ```
cyriltovena
approved these changes
Sep 10, 2024
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
This was referenced Oct 14, 2024
This was referenced Oct 21, 2024
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.
What this PR does / why we need it:
Small micro optimizations to save some allocations for the IP filter in logql.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Checklist
CONTRIBUTING.md
guide (required)feat
PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.docs/sources/setup/upgrade/_index.md
production/helm/loki/Chart.yaml
and updateproduction/helm/loki/CHANGELOG.md
andproduction/helm/loki/README.md
. Example PRdeprecated-config.yaml
anddeleted-config.yaml
files respectively in thetools/deprecated-config-checker
directory. Example PR