| 1 |
From 3f5169d0d5043342bbcf9bfd070e55fdb2a50b9c Mon Sep 17 00:00:00 2001 |
| 2 |
From: =?UTF-8?q?Ren=C3=A9?= <[email protected]> |
| 3 |
Date: Tue, 1 Sep 2026 08:34:40 +0200 |
| 4 |
Subject: [PATCH 4/4] test: cap fan-out nesting at depth 11 |
| 5 |
|
| 6 |
Go 1.27 generates type equality functions by flattened field shape rather |
| 7 |
than per named type, so every leaf is inlined into a single function instead |
| 8 |
of calling the child type's eq. fan19 carries 2^19 string leaves, which turns |
| 9 |
type:.eq into roughly 37 MB of code in one function; the compiler then stalls |
| 10 |
in stackalloc at 15+ GB RSS. That OOMs the 2vcpu CI runner and was reported |
| 11 |
as 45 GB on Debian's build daemons, which build the tests as part of |
| 12 |
packaging. |
| 13 |
|
| 14 |
Depth 11 keeps 2048 paths, still 4x maxDirectPaths, so the cap is exercised |
| 15 |
exactly as before and the direct map still fills to 512. Building the test |
| 16 |
binary under 1.27 drops from a stall to 2.1s at 534 MB peak RSS; the full |
| 17 |
suite with -race -count=15 -shuffle=on stays green on both 1.26.6 and 1.27.0. |
| 18 |
|
| 19 |
Closes #85 |
| 20 |
|
| 21 |
Signed-off-by: Daniel Baumann <[email protected]> |
| 22 |
--- |
| 23 |
fastpath_test.go | 40 +++++----------------------------------- |
| 24 |
1 file changed, 5 insertions(+), 35 deletions(-) |
| 25 |
|
| 26 |
diff --git a/fastpath_test.go b/fastpath_test.go |
| 27 |
index 26e13b5..0c598b5 100644 |
| 28 |
--- a/fastpath_test.go |
| 29 |
+++ b/fastpath_test.go |
| 30 |
@@ -323,45 +323,15 @@ type fan11 struct { |
| 31 |
A fan10 `schema:"a"` |
| 32 |
B fan10 `schema:"b"` |
| 33 |
} |
| 34 |
-type fan12 struct { |
| 35 |
- A fan11 `schema:"a"` |
| 36 |
- B fan11 `schema:"b"` |
| 37 |
-} |
| 38 |
-type fan13 struct { |
| 39 |
- A fan12 `schema:"a"` |
| 40 |
- B fan12 `schema:"b"` |
| 41 |
-} |
| 42 |
-type fan14 struct { |
| 43 |
- A fan13 `schema:"a"` |
| 44 |
- B fan13 `schema:"b"` |
| 45 |
-} |
| 46 |
-type fan15 struct { |
| 47 |
- A fan14 `schema:"a"` |
| 48 |
- B fan14 `schema:"b"` |
| 49 |
-} |
| 50 |
-type fan16 struct { |
| 51 |
- A fan15 `schema:"a"` |
| 52 |
- B fan15 `schema:"b"` |
| 53 |
-} |
| 54 |
-type fan17 struct { |
| 55 |
- A fan16 `schema:"a"` |
| 56 |
- B fan16 `schema:"b"` |
| 57 |
-} |
| 58 |
-type fan18 struct { |
| 59 |
- A fan17 `schema:"a"` |
| 60 |
- B fan17 `schema:"b"` |
| 61 |
-} |
| 62 |
-type fan19 struct { |
| 63 |
- A fan18 `schema:"a"` |
| 64 |
- B fan18 `schema:"b"` |
| 65 |
-} |
| 66 |
|
| 67 |
// Deep fan-out nesting has exponentially many dotted paths; the direct map |
| 68 |
// must stay capped so the first Decode neither stalls nor retains huge maps. |
| 69 |
+// Depth stays at 11 (2048 paths, 4x the cap): deeper trees blow up the Go 1.27 |
| 70 |
+// compiler, which flattens every leaf into a single generated equality func. |
| 71 |
func TestDirectPathsCappedForDeepFanout(t *testing.T) { |
| 72 |
d := NewDecoder() |
| 73 |
- var s fan19 |
| 74 |
- deepKey := strings.Repeat("a.", 10) + strings.Repeat("b.", 9) + "v" |
| 75 |
+ var s fan11 |
| 76 |
+ deepKey := strings.Repeat("a.", 6) + strings.Repeat("b.", 5) + "v" |
| 77 |
data := map[string][]string{deepKey: {"deep"}} |
| 78 |
done := make(chan error, 1) |
| 79 |
go func() { done <- d.Decode(&s, data) }() |
| 80 |
@@ -373,7 +343,7 @@ func TestDirectPathsCappedForDeepFanout(t *testing.T) { |
| 81 |
case <-time.After(30 * time.Second): |
| 82 |
t.Fatal("Decode stalled: direct-path precomputation not capped") |
| 83 |
} |
| 84 |
- if s.A.A.A.A.A.A.A.A.A.A.B.B.B.B.B.B.B.B.B.V != "deep" { |
| 85 |
+ if s.A.A.A.A.A.A.B.B.B.B.B.V != "deep" { |
| 86 |
t.Fatal("deep key not decoded") |
| 87 |
} |
| 88 |
info := d.cache.get(reflect.TypeOf(s)) |
| 89 |
-- |
| 90 |
2.55.0 |
| 91 |
|