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

perf(logql): Micro-optimizations for IP filter #14072

Merged
merged 5 commits into from
Sep 10, 2024

Commits on Sep 6, 2024

  1. 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%
    ```
    KasonBraley committed Sep 6, 2024
    Configuration menu
    Copy the full SHA
    0ef8b51 View commit details
    Browse the repository at this point in the history
  2. 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
    ```
    KasonBraley committed Sep 6, 2024
    Configuration menu
    Copy the full SHA
    de5ad9d View commit details
    Browse the repository at this point in the history
  3. 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%
    ```
    KasonBraley committed Sep 6, 2024
    Configuration menu
    Copy the full SHA
    75ca3d8 View commit details
    Browse the repository at this point in the history

Commits on Sep 10, 2024

  1. Configuration menu
    Copy the full SHA
    4841fe9 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1fe5d0d View commit details
    Browse the repository at this point in the history