@@ -1937,9 +1937,9 @@ func TestDecoder_InvalidSliceIndex(t *testing.T) {
19371937 Equal (t , v2 .PostIds [1 ], "2" )
19381938}
19391939
1940- // Issue #71: Nested structure decoding performance
1941- // https://github.com/go-playground/form/issues/71
1942- func TestIssue71NestedPerformance (t * testing.T ) {
1940+ // TestNestedArrayPerformance verifies decoding performance for nested structures.
1941+ // - Uses more lenient thresholds when race detector is enabled, since it can slow down execution.
1942+ func TestNestedArrayPerformance (t * testing.T ) {
19431943 type NestedBar struct {
19441944 Bazs []string `form:"bazs"`
19451945 Lookup map [string ]string `form:"lookup"`
@@ -1955,43 +1955,34 @@ func TestIssue71NestedPerformance(t *testing.T) {
19551955
19561956 decoder := NewDecoder ()
19571957
1958- // Adjust thresholds based on race detector
1959- // Race detector adds 5-10x overhead, especially on older Go versions
1960- // Using smaller counts (10, 50, 200) since we know the bug scales exponentially.
1961- // Without the fix, even 200 values would take 10+ seconds.
1962- var thresholds []struct {
1958+ var thresholdTests []struct {
19631959 numValues int
19641960 maxTime time.Duration
19651961 }
1966-
1962+
19671963 if raceEnabled {
1968- // Lenient thresholds for race detector mode (CI)
1969- t .Log ("Using lenient thresholds (race detector enabled)" )
1970- thresholds = []struct {
1964+ thresholdTests = []struct {
19711965 numValues int
19721966 maxTime time.Duration
19731967 }{
19741968 {10 , 50 * time .Millisecond },
1975- {50 , 500 * time .Millisecond }, // Without fix: ~5s, with fix: ~50-100ms
1976- {200 , 5 * time .Second }, // Without fix: ~80s+, with fix: ~500ms-2s
1969+ {50 , 500 * time .Millisecond },
1970+ {200 , 5 * time .Second },
19771971 }
19781972 } else {
1979- // Strict thresholds for normal mode (local dev)
1980- t .Log ("Using strict thresholds (race detector disabled)" )
1981- thresholds = []struct {
1973+ thresholdTests = []struct {
19821974 numValues int
19831975 maxTime time.Duration
19841976 }{
19851977 {10 , 10 * time .Millisecond },
1986- {50 , 50 * time .Millisecond }, // Without fix: ~1s, with fix: ~5-10ms
1987- {200 , 500 * time .Millisecond }, // Without fix: ~16s, with fix: ~50-100ms
1978+ {50 , 50 * time .Millisecond },
1979+ {200 , 500 * time .Millisecond },
19881980 }
19891981 }
19901982
1991- for _ , tt := range thresholds {
1983+ for _ , tt := range thresholdTests {
19921984 urlValues := make (url.Values )
19931985
1994- // Generate test data with nested structure
19951986 for i := 0 ; i < tt .numValues ; i ++ {
19961987 urlValues .Add (fmt .Sprintf ("foos[0].bars[%d].bazs" , i ), fmt .Sprintf ("value%d" , i ))
19971988 urlValues .Add (fmt .Sprintf ("foos[0].bars[%d].lookup[A]" , i ), fmt .Sprintf ("lookupA%d" , i ))
@@ -2006,24 +1997,21 @@ func TestIssue71NestedPerformance(t *testing.T) {
20061997 t .Errorf ("Decode error for %d values: %v" , tt .numValues , err )
20071998 }
20081999
2009- // Verify correct decoding
20102000 if len (req .Foos ) != 1 {
20112001 t .Errorf ("Expected 1 Foo, got %d" , len (req .Foos ))
20122002 }
20132003 if len (req .Foos [0 ].Bars ) != tt .numValues {
20142004 t .Errorf ("Expected %d Bars, got %d" , tt .numValues , len (req .Foos [0 ].Bars ))
20152005 }
20162006
2017- t .Logf ("%6d decoded values took: %v" , tt .numValues , elapsed )
2018-
20192007 if elapsed > tt .maxTime {
2020- t .Errorf ("Decoding %d values took %v, expected less than %v (performance regression?) " ,
2021- tt .numValues , elapsed , tt .maxTime )
2008+ t .Errorf ("[race=%t] Decoding %d values took %v, expected less than %v" ,
2009+ raceEnabled , tt .numValues , elapsed , tt .maxTime )
20222010 }
20232011 }
20242012}
20252013
2026- func BenchmarkIssue71Nested100 (b * testing.B ) {
2014+ func BenchmarkNestedArrayDecode100 (b * testing.B ) {
20272015 type NestedBar struct {
20282016 Bazs []string `form:"bazs"`
20292017 Lookup map [string ]string `form:"lookup"`
@@ -2054,7 +2042,7 @@ func BenchmarkIssue71Nested100(b *testing.B) {
20542042 }
20552043}
20562044
2057- func BenchmarkIssue71Nested1000 (b * testing.B ) {
2045+ func BenchmarkNestedArrayDecode1000 (b * testing.B ) {
20582046 type NestedBar struct {
20592047 Bazs []string `form:"bazs"`
20602048 Lookup map [string ]string `form:"lookup"`
0 commit comments