Skip to content

Poor performance when decoding data nested inside two collection layers #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Jecoms opened this issue Apr 25, 2025 · 0 comments
Open

Comments

@Jecoms
Copy link

Jecoms commented Apr 25, 2025

When decoding a struct that has data nested inside two layers of slices or maps, the performance is impacted exponentially based on the number of values.

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"`
}

// example payload to decode into FormRequest
var urlValues = url.Values{
  "foos[0].bars[0].bazs": []string{"..."},
  "foos[0].bars[0].lookup[A]": []string{"..."},
  ...
}

Go Playground

# ran on M3 MBP 18GB RAM
Slow first run
         1 decoded values took: 230.667µs

Decoder test without nesting
        10 decoded values took: 15.875µs
       100 decoded values took: 62.125µs
      1000 decoded values took: 621.334µs
     10000 decoded values took: 5.811209ms

Decoder test with layers of nesting
        10 decoded values took: 500.292µs
       100 decoded values took: 162.194542ms
      1000 decoded values took: 2m42.298277458s      
      # ... interrupted before 10000 completed ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant