• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

go-playground / form
100%

Build:
DEFAULT BRANCH: master
Repo Added 31 May 2016 09:37PM UTC
Files 6
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

LAST BUILD ON BRANCH master
branch: SELECT
CHANGE BRANCH
x
  • No branch selected
  • add-embedded-struct-support
  • custom-tag-fn
  • decode-encode-all-types
  • encoder
  • fix-array-handling
  • fix-encoder-pointer-omitempty
  • fix-index-exception
  • fix-issue-71-nested-performance
  • fix-pointer-decoder-panic
  • fix-slice-idx-issue
  • fixes
  • interface-support
  • master
  • minor-perf-2
  • minor-perf-3
  • minor-perf-4
  • minor-perf-5
  • minor-perf-updates
  • retract-v4.2.2
  • revert-68-fix-pointer-decoder-panic
  • update-test-dep
  • update-to-go-modules
  • v4.0.0
  • v4.1.0
  • v4.1.1
  • v4.1.2

11 Oct 2025 05:04PM UTC coverage: 99.723% (-0.09%) from 99.814%
18432284340

push

github

web-flow
Improve issue #71: Optimize nested structure decoding performance (#73)

## Problem
When decoding structs with data nested inside two or more layers of
slices or maps, the decoder exhibited exponential performance
degradation based on the number of values.

### Example Structure
```go
type FormRequest struct {
Foos []*NestedFoo `form:"foos"`
}

type NestedFoo struct {
Bars []*NestedBar `form:"bars"`
}

type NestedBar struct {
Bazs   []string          `form:"bazs"`
Lookup map[string]string `form:"lookup"`
}
```

### Performance Before Fix
- 50 values: ~1 second
- 100 values: ~4 seconds  
- 200 values: ~16 seconds

The performance degradation was exponential, making the decoder unusable
for real-world nested data.

## Root Cause
The `findAlias()` function performed a **linear O(n) search** through
the `dataMap` slice for every alias lookup. With deeply nested
structures, this function was called thousands or millions of times,
resulting in O(n²) or worse complexity.

For example, with 1000 nested elements, the parser would:
1. Create ~1002 unique aliases (1 for `foos`, 1 for `foos[0].bars`, 1000
for `foos[0].bars[N].lookup`)
2. Call `findAlias()` many times during parsing and decoding
3. Each `findAlias()` call would iterate through the entire dataMap
linearly

## Solution
Replaced the linear search with a **hash map lookup (O(1))**:

1. Added `aliasMap map[string]*recursiveData` field to the `decoder`
struct
2. Modified `parseMapData()` to populate the map as aliases are created
3. Changed `findAlias()` to use the map instead of iterating through the
slice

### Code Changes
**decoder.go:**
- Added `aliasMap` field to `decoder` struct for O(1) lookups
- Initialized/cleared the map in `parseMapData()`  
- Populated the map when creating new `recursiveData` entries
- Modified `findAlias()` to use map lookup instead of linear search

**decoder_test.go:**
- Added comprehensive test with 10, 50, and 200 nested values
- Uses race-detector-aware thresholds (st... (continued)

9 of 9 new or added lines in 1 file covered. (100.0%)

1 existing line in 1 file now uncovered.

1080 of 1083 relevant lines covered (99.72%)

43077.28 hits per line

Relevant lines Covered
Build:
Build:
1083 RELEVANT LINES 1080 COVERED LINES
43077.28 HITS PER LINE
Source Files on master
  • List 6
  • Changed 1
  • Source Changed 0
  • Coverage Changed 1
Coverage ∆ File Lines Relevant Covered Missed Hits/Line

Recent builds

Builds Branch Commit Type Ran Committer Via Coverage
18432284340 master Improve issue #71: Optimize nested structure decoding performance (#73) ## Problem When decoding structs with data nested inside two or more layers of slices or maps, the decoder exhibited exponential performance degradation based on the number o... push 11 Oct 2025 05:05PM UTC web-flow github
99.72
18267045333 fix-issue-71-nested-performance Improve nested structure decoding performance Optimize nested structure decoding by replacing O(n) linear search with O(1) hash map lookup in the findAlias function. Changes: - Add aliasMap (map[string]*recursiveData) to decoder struct for O(1) ... Pull #73 06 Oct 2025 01:04AM UTC web-flow github
99.72
18266965012 fix-issue-71-nested-performance Rename issue-specific tests to generic names - Rename TestIssue71NestedPerformance to TestNestedArrayPerformance - Rename BenchmarkIssue71Nested100 to BenchmarkNestedArrayDecode100 - Rename BenchmarkIssue71Nested1000 to BenchmarkNestedArrayDecode... Pull #73 06 Oct 2025 12:58AM UTC web-flow github
99.72
18239222419 fix-issue-71-nested-performance Use smaller test counts to reduce CI time while still detecting regression Changed from (10, 100, 1000) to (10, 50, 200) values. Since the bug scales exponentially, 200 values is sufficient to prove the optimization works (without fix: 16s+, wit... Pull #73 04 Oct 2025 03:52AM UTC Jecoms github
99.72
13994600204 master retract breaking change (#70) ## Fixes Or Enhances **Make sure that you've checked the boxes below before you submit PR:** - [ ] Tests exist or have been written that cover this particular change. @go-playground/admins push 21 Mar 2025 02:58PM UTC web-flow github
99.81
13994551050 retract-v4.2.2 retract breaking change Pull #70 21 Mar 2025 02:55PM UTC deankarn github
99.81
13994468644 master Revert "Fix panic when the decoding pointer type with custom decoding function" (#69) Reverts go-playground/form#68 push 21 Mar 2025 02:51PM UTC web-flow github
99.81
13994411058 revert-68-fix-pointer-decoder-panic Revert "Fix panic when the decoding pointer type with custom decoding functio…" This reverts commit 212b1c48a. Pull #69 21 Mar 2025 02:48PM UTC web-flow github
99.81
13938521593 master Update README.md push 19 Mar 2025 03:54AM UTC web-flow github
99.82
13938478981 master Fix panic when the decoding pointer type with custom decoding function (#68) ## Fixes Or Enhances When a pointer type has a custom decoder and the decoded value is nil, we get a panic. Example ```go func main() { type CustomTime *time.Time ... push 19 Mar 2025 03:50AM UTC web-flow github
99.82
See All Builds (159)
  • Repo on GitHub
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc