RuleGroup: use stdlib for json decoding, optimize decoding - #2109
Merged
Conversation
Baseline benchmark go1.26.6 test ./api/prometheus/v1 -bench RuleGroup -benchmem -run ^$ -count=6 goos: darwin goarch: arm64 pkg: github.com/prometheus/client_golang/api/prometheus/v1 cpu: Apple M4 Pro BenchmarkRuleGroup/streaming-14 1059 945867 ns/op 1324909 B/op 27396 allocs/op BenchmarkRuleGroup/streaming-14 1258 946632 ns/op 1324947 B/op 27396 allocs/op BenchmarkRuleGroup/streaming-14 1298 936014 ns/op 1324919 B/op 27396 allocs/op BenchmarkRuleGroup/streaming-14 1275 942051 ns/op 1324939 B/op 27396 allocs/op BenchmarkRuleGroup/streaming-14 1280 949613 ns/op 1324919 B/op 27396 allocs/op BenchmarkRuleGroup/streaming-14 1272 943165 ns/op 1324928 B/op 27396 allocs/op BenchmarkRuleGroup/unmarshal-14 1358 884021 ns/op 1021988 B/op 27314 allocs/op BenchmarkRuleGroup/unmarshal-14 1347 885628 ns/op 1021997 B/op 27314 allocs/op BenchmarkRuleGroup/unmarshal-14 1353 892039 ns/op 1021991 B/op 27314 allocs/op BenchmarkRuleGroup/unmarshal-14 1330 886184 ns/op 1021980 B/op 27314 allocs/op BenchmarkRuleGroup/unmarshal-14 1359 884447 ns/op 1021998 B/op 27314 allocs/op BenchmarkRuleGroup/unmarshal-14 1350 890479 ns/op 1022020 B/op 27314 allocs/op PASS ok github.com/prometheus/client_golang/api/prometheus/v1 15.595s Signed-off-by: Jordan Liggitt <liggitt@google.com>
Benchmark delta on go1.26.6
goos: darwin
goarch: arm64
pkg: github.com/prometheus/client_golang/api/prometheus/v1
cpu: Apple M4 Pro
│ 1-jsoniter.txt │ 2-gojson.txt │
│ sec/op │ sec/op vs base │
RuleGroup/streaming-14 944.5µ ± 1% 2083.1µ ± 1% +120.54% (p=0.002 n=6)
RuleGroup/unmarshal-14 885.9µ ± 1% 2143.6µ ± 2% +141.97% (p=0.002 n=6)
geomean 914.7µ 2.113m +131.01%
│ 1-jsoniter.txt │ 2-gojson.txt │
│ B/op │ B/op vs base │
RuleGroup/streaming-14 1293.9Ki ± 0% 962.7Ki ± 0% -25.60% (p=0.002 n=6)
RuleGroup/unmarshal-14 998.0Ki ± 0% 708.2Ki ± 0% -29.05% (p=0.002 n=6)
geomean 1.110Mi 825.7Ki -27.34%
│ 1-jsoniter.txt │ 2-gojson.txt │
│ allocs/op │ allocs/op vs base │
RuleGroup/streaming-14 27.40k ± 0% 11.92k ± 0% -56.49% (p=0.002 n=6)
RuleGroup/unmarshal-14 27.31k ± 0% 11.91k ± 0% -56.41% (p=0.002 n=6)
geomean 27.35k 11.91k -56.45%
Signed-off-by: Jordan Liggitt <liggitt@google.com>
goos: darwin
goarch: arm64
pkg: github.com/prometheus/client_golang/api/prometheus/v1
cpu: Apple M4 Pro
│ 2-gojson.txt │ 3-typefield.txt │
│ sec/op │ sec/op vs base │
RuleGroup/streaming-14 2.083m ± 1% 1.606m ± 0% -22.93% (p=0.002 n=6)
RuleGroup/unmarshal-14 2.144m ± 2% 1.604m ± 3% -25.18% (p=0.002 n=6)
geomean 2.113m 1.605m -24.06%
│ 2-gojson.txt │ 3-typefield.txt │
│ B/op │ B/op vs base │
RuleGroup/streaming-14 962.7Ki ± 0% 832.7Ki ± 0% -13.50% (p=0.002 n=6)
RuleGroup/unmarshal-14 708.2Ki ± 0% 578.3Ki ± 0% -18.33% (p=0.002 n=6)
geomean 825.7Ki 693.9Ki -15.95%
│ 2-gojson.txt │ 3-typefield.txt │
│ allocs/op │ allocs/op vs base │
RuleGroup/streaming-14 11.920k ± 0% 9.614k ± 0% -19.35% (p=0.002 n=6)
RuleGroup/unmarshal-14 11.907k ± 0% 9.601k ± 0% -19.37% (p=0.002 n=6)
geomean 11.91k 9.607k -19.36%
Signed-off-by: Jordan Liggitt <liggitt@google.com>
goos: darwin
goarch: arm64
pkg: github.com/prometheus/client_golang/api/prometheus/v1
cpu: Apple M4 Pro
│ 3-typefield.txt │ 4-structcopy.txt │
│ sec/op │ sec/op vs base │
RuleGroup/streaming-14 1.606m ± 0% 1.552m ± 0% -3.35% (p=0.002 n=6)
RuleGroup/unmarshal-14 1.604m ± 3% 1.522m ± 1% -5.13% (p=0.002 n=6)
geomean 1.605m 1.537m -4.25%
│ 3-typefield.txt │ 4-structcopy.txt │
│ B/op │ B/op vs base │
RuleGroup/streaming-14 832.7Ki ± 0% 832.7Ki ± 0% ~ (p=0.418 n=6)
RuleGroup/unmarshal-14 578.3Ki ± 0% 578.3Ki ± 0% ~ (p=0.197 n=6)
geomean 693.9Ki 693.9Ki -0.00%
│ 3-typefield.txt │ 4-structcopy.txt │
│ allocs/op │ allocs/op vs base │
RuleGroup/streaming-14 9.614k ± 0% 9.614k ± 0% ~ (p=1.000 n=6) ¹
RuleGroup/unmarshal-14 9.601k ± 0% 9.601k ± 0% ~ (p=1.000 n=6) ¹
geomean 9.607k 9.607k +0.00%
Signed-off-by: Jordan Liggitt <liggitt@google.com>
bwplotka
reviewed
Sep 9, 2026
This file contains hidden or 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
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.
cc @bwplotka
part of #2105
Allocs and bytes consumed are significantly better than json-iter on both Go 1.26 and 1.27
CPU is worse on Go 1.26, better on Go 1.27.