• 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: master
CHANGE BRANCH
x
Reset
  • master
  • 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
  • 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
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
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
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
13933039231 master Fix panic when the decoding pointer type with custom decoding function Pull #67 18 Mar 2025 08:38PM UTC adityarsuryavamshi github
99.82
13932695007 master Change module name This is just temporary to work against this fork, before the core change is merged upstair Pull #67 18 Mar 2025 08:18PM UTC adityarsuryavamshi github
99.82
13932238280 master Fix panic when the decoding pointer type with custom decoding function Pull #67 18 Mar 2025 07:51PM UTC adityarsuryavamshi github
99.82
5545626869 master Handle invalid Slice/Array indexes better (#61) push 13 Jul 2023 04:36PM UTC web-flow github
99.81
1010449026 master Update README.md push 08 Jul 2021 05:00AM UTC GitHub github
99.81
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