-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Commits on Sep 6, 2024
-
perf(logql): Save 2 allocations in IP filter
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% ```
Configuration menu - View commit details
-
Copy full SHA for 0ef8b51 - Browse repository at this point
Copy the full SHA 0ef8b51View commit details -
perf(logql): Use struct for map value to save some bytes
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 ```
Configuration menu - View commit details
-
Copy full SHA for de5ad9d - Browse repository at this point
Copy the full SHA de5ad9dView commit details -
perf(logql): Use array instead of map to save 5 more allocs
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% ```
Configuration menu - View commit details
-
Copy full SHA for 75ca3d8 - Browse repository at this point
Copy the full SHA 75ca3d8View commit details
Commits on Sep 10, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 4841fe9 - Browse repository at this point
Copy the full SHA 4841fe9View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1fe5d0d - Browse repository at this point
Copy the full SHA 1fe5d0dView commit details
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.