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

Intern label keys for LogQL parser. #3990

Merged
merged 3 commits into from
Jul 14, 2021

Conversation

cyriltovena
Copy link
Contributor

They often will see the same key over and over and instead of allocating/sanitizing we can re-use the previous value.
This mostly speeds up parser that were using a dynamic list of keys like json and logfmt.

We could intern values too specially for metrics queries.

❯ benchcmp  before.txt after.txt
benchmark                                                   old ns/op     new ns/op     delta
Benchmark_Parser/json/no_labels_hints-16                    3894          2885          -25.91%
Benchmark_Parser/json/labels_hints-16                       2084          2163          +3.79%
Benchmark_Parser/unpack/no_labels_hints-16                  915           890           -2.72%
Benchmark_Parser/unpack/labels_hints-16                     848           846           -0.32%
Benchmark_Parser/logfmt/no_labels_hints-16                  2229          1146          -48.59%
Benchmark_Parser/logfmt/labels_hints-16                     1230          1150          -6.50%
Benchmark_Parser/regex_greedy/no_labels_hints-16            3881          3754          -3.27%
Benchmark_Parser/regex_greedy/labels_hints-16               5443          3737          -31.34%
Benchmark_Parser/regex_status_digits/no_labels_hints-16     318           290           -8.89%
Benchmark_Parser/regex_status_digits/labels_hints-16        335           289           -13.85%
Benchmark_Parser/pattern/no_labels_hints-16                 151           151           -0.20%
Benchmark_Parser/pattern/labels_hints-16                    129           131           +1.24%

benchmark                                                   old allocs     new allocs     delta
Benchmark_Parser/json/no_labels_hints-16                    69             43             -37.68%
Benchmark_Parser/json/labels_hints-16                       32             36             +12.50%
Benchmark_Parser/unpack/no_labels_hints-16                  19             17             -10.53%
Benchmark_Parser/unpack/labels_hints-16                     16             17             +6.25%
Benchmark_Parser/logfmt/no_labels_hints-16                  46             16             -65.22%
Benchmark_Parser/logfmt/labels_hints-16                     20             16             -20.00%
Benchmark_Parser/regex_greedy/no_labels_hints-16            2              2              +0.00%
Benchmark_Parser/regex_greedy/labels_hints-16               2              2              +0.00%
Benchmark_Parser/regex_status_digits/no_labels_hints-16     2              2              +0.00%
Benchmark_Parser/regex_status_digits/labels_hints-16        2              2              +0.00%
Benchmark_Parser/pattern/no_labels_hints-16                 2              2              +0.00%
Benchmark_Parser/pattern/labels_hints-16                    1              1              +0.00%

benchmark                                                   old bytes     new bytes     delta
Benchmark_Parser/json/no_labels_hints-16                    1089          624           -42.70%
Benchmark_Parser/json/labels_hints-16                       456           480           +5.26%
Benchmark_Parser/unpack/no_labels_hints-16                  569           537           -5.62%
Benchmark_Parser/unpack/labels_hints-16                     553           537           -2.89%
Benchmark_Parser/logfmt/no_labels_hints-16                  576           336           -41.67%
Benchmark_Parser/logfmt/labels_hints-16                     256           336           +31.25%
Benchmark_Parser/regex_greedy/no_labels_hints-16            194           194           +0.00%
Benchmark_Parser/regex_greedy/labels_hints-16               194           194           +0.00%
Benchmark_Parser/regex_status_digits/no_labels_hints-16     52            52            +0.00%
Benchmark_Parser/regex_status_digits/labels_hints-16        52            52            +0.00%
Benchmark_Parser/pattern/no_labels_hints-16                 35            35            +0.00%
Benchmark_Parser/pattern/labels_hints-16                    32            32            +0.00%

Signed-off-by: Cyril Tovena cyril.tovena@gmail.com

They often will see the same key over and over and instead of allocating/sanitizing we can re-use the previous value.
This mostly speeds up parser that were using a dynamic list of keys like json and logfmt.

We could intern values too specially for metrics queries.

```
❯ benchcmp  before.txt after.txt
benchmark                                                   old ns/op     new ns/op     delta
Benchmark_Parser/json/no_labels_hints-16                    3894          2885          -25.91%
Benchmark_Parser/json/labels_hints-16                       2084          2163          +3.79%
Benchmark_Parser/unpack/no_labels_hints-16                  915           890           -2.72%
Benchmark_Parser/unpack/labels_hints-16                     848           846           -0.32%
Benchmark_Parser/logfmt/no_labels_hints-16                  2229          1146          -48.59%
Benchmark_Parser/logfmt/labels_hints-16                     1230          1150          -6.50%
Benchmark_Parser/regex_greedy/no_labels_hints-16            3881          3754          -3.27%
Benchmark_Parser/regex_greedy/labels_hints-16               5443          3737          -31.34%
Benchmark_Parser/regex_status_digits/no_labels_hints-16     318           290           -8.89%
Benchmark_Parser/regex_status_digits/labels_hints-16        335           289           -13.85%
Benchmark_Parser/pattern/no_labels_hints-16                 151           151           -0.20%
Benchmark_Parser/pattern/labels_hints-16                    129           131           +1.24%

benchmark                                                   old allocs     new allocs     delta
Benchmark_Parser/json/no_labels_hints-16                    69             43             -37.68%
Benchmark_Parser/json/labels_hints-16                       32             36             +12.50%
Benchmark_Parser/unpack/no_labels_hints-16                  19             17             -10.53%
Benchmark_Parser/unpack/labels_hints-16                     16             17             +6.25%
Benchmark_Parser/logfmt/no_labels_hints-16                  46             16             -65.22%
Benchmark_Parser/logfmt/labels_hints-16                     20             16             -20.00%
Benchmark_Parser/regex_greedy/no_labels_hints-16            2              2              +0.00%
Benchmark_Parser/regex_greedy/labels_hints-16               2              2              +0.00%
Benchmark_Parser/regex_status_digits/no_labels_hints-16     2              2              +0.00%
Benchmark_Parser/regex_status_digits/labels_hints-16        2              2              +0.00%
Benchmark_Parser/pattern/no_labels_hints-16                 2              2              +0.00%
Benchmark_Parser/pattern/labels_hints-16                    1              1              +0.00%

benchmark                                                   old bytes     new bytes     delta
Benchmark_Parser/json/no_labels_hints-16                    1089          624           -42.70%
Benchmark_Parser/json/labels_hints-16                       456           480           +5.26%
Benchmark_Parser/unpack/no_labels_hints-16                  569           537           -5.62%
Benchmark_Parser/unpack/labels_hints-16                     553           537           -2.89%
Benchmark_Parser/logfmt/no_labels_hints-16                  576           336           -41.67%
Benchmark_Parser/logfmt/labels_hints-16                     256           336           +31.25%
Benchmark_Parser/regex_greedy/no_labels_hints-16            194           194           +0.00%
Benchmark_Parser/regex_greedy/labels_hints-16               194           194           +0.00%
Benchmark_Parser/regex_status_digits/no_labels_hints-16     52            52            +0.00%
Benchmark_Parser/regex_status_digits/labels_hints-16        52            52            +0.00%
Benchmark_Parser/pattern/no_labels_hints-16                 35            35            +0.00%
Benchmark_Parser/pattern/labels_hints-16                    32            32            +0.00%
```

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
…1024.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
@owen-d owen-d merged commit 5d8414f into grafana:main Jul 14, 2021
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.

2 participants