From ef91ad619a60adaafcf6828355c4dc1d25ee067b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Efe=20=C3=87etin?= Date: Tue, 12 Apr 2022 11:38:58 +0300 Subject: [PATCH 1/3] add missing config fields, add new guide about speed. --- SUMMARY.md | 1 + api/fiber.md | 4 ++++ guide/faster-fiber.md | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 guide/faster-fiber.md diff --git a/SUMMARY.md b/SUMMARY.md index 0c7acc00ca1..f49c1d37b1e 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -39,6 +39,7 @@ * [🐛 Error Handling](guide/error-handling.md) * [🔎 Validation](guide/validation.md) * [🪝 Hooks](guide/hooks.md) +* [⚡ Make Fiber Faster](guide/faster-fiber.md) ## Extra diff --git a/api/fiber.md b/api/fiber.md index 14d47c5b29a..b05f687d8b4 100644 --- a/api/fiber.md +++ b/api/fiber.md @@ -78,6 +78,10 @@ app := fiber.New(fiber.Config{ | DisablePreParseMultipartForm | `bool` | Will not pre parse Multipart Form data if set to true. This option is useful for servers that desire to treat multipart form data as a binary blob, or choose when to parse the data. | `false` | | StreamRequestBody | `bool` | StreamRequestBody enables request body streaming, and calls the handler sooner when given body is larger then the current limit. | `false` | | EnablePrintRoutes | `bool` | EnablePrintRoutes enables print all routes with their method, path, name and handler.. | `false` | +| Network | `string` | Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only)

**WARNING:** When prefork is set to true, only "tcp4" and "tcp6" can be chosen. | `NetworkTCP4` | +| JSONEncoder | `utils.JSONMarshal` | Allowing for flexibility in using another json library for encoding. | `json.Marshal` | +| JSONDecoder | `utils.JSONUnmarshal` | Allowing for flexibility in using another json library for decoding. | `json.Unmarshal` | + ## NewError diff --git a/guide/faster-fiber.md b/guide/faster-fiber.md new file mode 100644 index 00000000000..9ad4e337096 --- /dev/null +++ b/guide/faster-fiber.md @@ -0,0 +1,19 @@ +# ⚡ Make Fiber Faster + +## Custom JSON Encoder/Decoder +Since Fiber v2.32.0, we use **encoding/json** as default json library due to stability and producibility. However, the standard library is a bit slow compared to 3rd party libraries. If you're not happy with the performance of **encoding/json**, we recommend you to use these libraries: +- [goccy/go-json]() +- [bytedance/sonic]() +- [segmentio/encoding]() + +{% code title="Example" %} +```go +func (app *App) OnShutdown(handler ...OnShutdownHandler) +``` +{% endcode %} + +### References +- [Set custom JSON encoder for client](../api/client.md#jsonencoder) +- [Set custom JSON decoder for client](../api/client.md#jsondecoder) +- [Set custom JSON encoder for application](../api/fiber.md#config) +- [Set custom JSON decoder for application](../api/fiber.md#config) \ No newline at end of file From df5c153ca3dfb5d3b89699c2653b6b0cb95a4667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Efe=20=C3=87etin?= Date: Tue, 12 Apr 2022 11:43:21 +0300 Subject: [PATCH 2/3] update --- guide/faster-fiber.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/guide/faster-fiber.md b/guide/faster-fiber.md index 9ad4e337096..25ca07d4618 100644 --- a/guide/faster-fiber.md +++ b/guide/faster-fiber.md @@ -2,13 +2,25 @@ ## Custom JSON Encoder/Decoder Since Fiber v2.32.0, we use **encoding/json** as default json library due to stability and producibility. However, the standard library is a bit slow compared to 3rd party libraries. If you're not happy with the performance of **encoding/json**, we recommend you to use these libraries: -- [goccy/go-json]() -- [bytedance/sonic]() -- [segmentio/encoding]() +- [goccy/go-json](https://github.com/goccy/go-json1) +- [bytedance/sonic](https://github.com/bytedance/sonic) +- [segmentio/encoding](https://github.com/segmentio/encoding) {% code title="Example" %} ```go -func (app *App) OnShutdown(handler ...OnShutdownHandler) +package main + +import "github.com/gofiber/fiber/v2" +import "github.com/goccy/go-json" + +func main() { + app := fiber.New(fiber.Config{ + JSONEncoder: json.Marshal, + JSONDecoder: json.Unmarshal, + }) + + # ... +} ``` {% endcode %} From e7a18604dfd3c653fc0a4015f63d1fa7a5931b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Efe=20=C3=87etin?= Date: Tue, 12 Apr 2022 11:45:41 +0300 Subject: [PATCH 3/3] add more libs. --- guide/faster-fiber.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/guide/faster-fiber.md b/guide/faster-fiber.md index 25ca07d4618..6cbc451ffbf 100644 --- a/guide/faster-fiber.md +++ b/guide/faster-fiber.md @@ -5,6 +5,9 @@ Since Fiber v2.32.0, we use **encoding/json** as default json library due to sta - [goccy/go-json](https://github.com/goccy/go-json1) - [bytedance/sonic](https://github.com/bytedance/sonic) - [segmentio/encoding](https://github.com/segmentio/encoding) +- [mailru/easyjson](https://github.com/mailru/easyjson) +- [minio/simdjson-go](https://github.com/minio/simdjson-go) +- [wI2L/jettison](https://github.com/wI2L/jettison) {% code title="Example" %} ```go