perf(decode): parse struct destinations without the value tree
Test / test (push) Successful in 1m50s

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-22 15:59:03 +02:00
parent ee32490452
commit a7d0041259
7 changed files with 1971 additions and 6 deletions
+37
View File
@@ -4,6 +4,7 @@
package interpres
import (
"context"
"fmt"
"strings"
"testing"
@@ -168,3 +169,39 @@ func BenchmarkMarshalLong(b *testing.B) {
}
}
}
// BenchmarkStrictDecodeTree measures the reference path the targeted decode
// is measured against: the full tree parse followed by the reflection walk.
// The pair runs in one process, so the A/B comparison shares the machine.
func BenchmarkStrictDecodeTree(b *testing.B) {
dec := newDecoder()
dec.disallowUnknown = true
b.ReportAllocs()
for b.Loop() {
tree, _, err := parseWithOptions(context.Background(), benchDoc, parseOptions{}, false)
if err != nil {
b.Fatal(err)
}
var cfg benchConfig
if err := dec.decode(tree, &cfg); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkStrictDecodeTreeLong(b *testing.B) {
dec := newDecoder()
dec.disallowUnknown = true
b.ReportAllocs()
b.SetBytes(int64(len(longDoc)))
for b.Loop() {
tree, _, err := parseWithOptions(context.Background(), longDoc, parseOptions{}, false)
if err != nil {
b.Fatal(err)
}
var doc benchLongDoc
if err := dec.decode(tree, &doc); err != nil {
b.Fatal(err)
}
}
}