Skip to content
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

🚀 v3 Request: New Parser for Binding #2002

Open
3 tasks done
efectn opened this issue Aug 8, 2022 · 6 comments · May be fixed by #2006
Open
3 tasks done

🚀 v3 Request: New Parser for Binding #2002

efectn opened this issue Aug 8, 2022 · 6 comments · May be fixed by #2006
Assignees
Milestone

Comments

@efectn
Copy link
Member

efectn commented Aug 8, 2022

Feature Description

Currently, Fiber binding uses gorilla/schema and it's very slow and doesn't support multipart files (#1967).

We should write more performant, powerful parser acording to the needs of Fiber.

Check: #1981 (comment)

Additional Context (optional)

No response

Code Snippet (optional)

package main

import "github.com/gofiber/fiber/v2"
import "log"

func main() {
  app := fiber.New()

  // An example to describe the feature

  log.Fatal(app.Listen(":3000"))
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my suggestion prior to opening this one.
  • I understand that improperly formatted feature requests may be closed without explanation.
@efectn efectn added this to the v3 milestone Aug 8, 2022
@efectn efectn added this to v3 Aug 8, 2022
@efectn efectn changed the title 🚀 v3 [Feature]: New Parser for Binding 🚀 v3 Request: New Parser for Binding Aug 8, 2022
@trim21
Copy link
Contributor

trim21 commented Aug 8, 2022

I'd like to add another context about this impl.

Key point here is not to use methods of fiber.Ctx, but to build a decoder for a Request struct and reuse it in the future.

with a function decorator, the decoder are pre-compiled and cached by nature. and this cached don't have overhead like map access.

If the decoder is not pre-compiled, it's not that fast and low alloc:

func Benchmark_lib_unmarshal(b *testing.B) {
	decode := inj.CompileParser(Req{})
	ctx := getCtx()
	for i := 0; i < b.N; i++ {
		_, err := decode(ctx)
		if err != nil {
			b.Error(err)
			b.FailNow()
		}
	}
}

func Benchmark_lib_unmarshal_with_compile(b *testing.B) {
- 	decode := inj.CompileParser(Req{})
	ctx := getCtx()
	for i := 0; i < b.N; i++ {
+		decode := inj.CompileParser(Req{})
		_, err := decode(ctx)
		if err != nil {
			b.Error(err)
			b.FailNow()
		}
	}
}
cpu: AMD Ryzen 7 5800X 8-Core Processor
Benchmark_unmarshal_by_hand-16                          14774758                68.03 ns/op            0 B/op          0 allocs/op
Benchmark_lib_unmarshal-16                               6359373               196.7 ns/op            96 B/op          2 allocs/op
Benchmark_lib_unmarshal_with_compile-16                  1222078               992.6 ns/op           672 B/op         22 allocs/op
BenchmarkGorillaSchema_map_to_struct_only-16              419390              2898 ns/op             904 B/op         49 allocs/op

@ReneWerner87
Copy link
Member

if you have ideas or performance improvements, feel free to create a pull request with them and we'll see together how to get the best out of the respective functionalities.

any comments or improvements are always welcome

once the whole thing is released, it's hard to bend it, because non downward compatible changes require a new major version

@trim21
Copy link
Contributor

trim21 commented Aug 8, 2022

I'll send a PR later

@efectn efectn moved this to Todo in v3 Aug 8, 2022
@trim21 trim21 linked a pull request Aug 8, 2022 that will close this issue
20 tasks
@wangjq4214
Copy link
Member

I want to know if the minimum go version that will be supported in the next release will be 1.18?

@trim21
Copy link
Contributor

trim21 commented Aug 8, 2022

I guess yes https://github.com/gofiber/fiber/blob/v3-beta/go.mod#L3 , and my pr need new generic support .

@efectn
Copy link
Member Author

efectn commented Aug 9, 2022

I want to know if the minimum go version that will be supported in the next release will be 1.18?

Yes. v3 will support last 2 major versions of Go

@efectn efectn linked a pull request Aug 11, 2022 that will close this issue
20 tasks
@efectn efectn moved this from Todo to In Progress in v3 Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

4 participants