From 3f5169d0d5043342bbcf9bfd070e55fdb2a50b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Tue, 1 Sep 2026 08:34:40 +0200 Subject: [PATCH 4/4] test: cap fan-out nesting at depth 11 Go 1.27 generates type equality functions by flattened field shape rather than per named type, so every leaf is inlined into a single function instead of calling the child type's eq. fan19 carries 2^19 string leaves, which turns type:.eq into roughly 37 MB of code in one function; the compiler then stalls in stackalloc at 15+ GB RSS. That OOMs the 2vcpu CI runner and was reported as 45 GB on Debian's build daemons, which build the tests as part of packaging. Depth 11 keeps 2048 paths, still 4x maxDirectPaths, so the cap is exercised exactly as before and the direct map still fills to 512. Building the test binary under 1.27 drops from a stall to 2.1s at 534 MB peak RSS; the full suite with -race -count=15 -shuffle=on stays green on both 1.26.6 and 1.27.0. Closes #85 Signed-off-by: Daniel Baumann --- fastpath_test.go | 40 +++++----------------------------------- 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/fastpath_test.go b/fastpath_test.go index 26e13b5..0c598b5 100644 --- a/fastpath_test.go +++ b/fastpath_test.go @@ -323,45 +323,15 @@ type fan11 struct { A fan10 `schema:"a"` B fan10 `schema:"b"` } -type fan12 struct { - A fan11 `schema:"a"` - B fan11 `schema:"b"` -} -type fan13 struct { - A fan12 `schema:"a"` - B fan12 `schema:"b"` -} -type fan14 struct { - A fan13 `schema:"a"` - B fan13 `schema:"b"` -} -type fan15 struct { - A fan14 `schema:"a"` - B fan14 `schema:"b"` -} -type fan16 struct { - A fan15 `schema:"a"` - B fan15 `schema:"b"` -} -type fan17 struct { - A fan16 `schema:"a"` - B fan16 `schema:"b"` -} -type fan18 struct { - A fan17 `schema:"a"` - B fan17 `schema:"b"` -} -type fan19 struct { - A fan18 `schema:"a"` - B fan18 `schema:"b"` -} // Deep fan-out nesting has exponentially many dotted paths; the direct map // must stay capped so the first Decode neither stalls nor retains huge maps. +// Depth stays at 11 (2048 paths, 4x the cap): deeper trees blow up the Go 1.27 +// compiler, which flattens every leaf into a single generated equality func. func TestDirectPathsCappedForDeepFanout(t *testing.T) { d := NewDecoder() - var s fan19 - deepKey := strings.Repeat("a.", 10) + strings.Repeat("b.", 9) + "v" + var s fan11 + deepKey := strings.Repeat("a.", 6) + strings.Repeat("b.", 5) + "v" data := map[string][]string{deepKey: {"deep"}} done := make(chan error, 1) go func() { done <- d.Decode(&s, data) }() @@ -373,7 +343,7 @@ func TestDirectPathsCappedForDeepFanout(t *testing.T) { case <-time.After(30 * time.Second): t.Fatal("Decode stalled: direct-path precomputation not capped") } - if s.A.A.A.A.A.A.A.A.A.A.B.B.B.B.B.B.B.B.B.V != "deep" { + if s.A.A.A.A.A.A.B.B.B.B.B.V != "deep" { t.Fatal("deep key not decoded") } info := d.cache.get(reflect.TypeOf(s)) -- 2.55.0