Skip to content

Commit

Permalink
Add zero-allocation section to README (#3039)
Browse files Browse the repository at this point in the history
Add zero-allocation section README
  • Loading branch information
gaby authored Jun 20, 2024
1 parent 011e83b commit 5914e92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 6 additions & 2 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</a>
</p>
<p align="center">
<em><b>Fiber</b> is an <a href="https://github.com/expressjs/express">Express</a> inspired <b>web framework</b> built on top of <a href="https://github.com/valyala/fasthttp">Fasthttp</a>, the <b>fastest</b> HTTP engine for <a href="https://go.dev/doc/">Go</a>. Designed to <b>ease</b> things up for <b>fast</b> development with <b>zero memory allocation</b> and <b>performance</b> in mind.</em>
<em><b>Fiber</b> is an <a href="https://github.com/expressjs/express">Express</a> inspired <b>web framework</b> built on top of <a href="https://github.com/valyala/fasthttp">Fasthttp</a>, the <b>fastest</b> HTTP engine for <a href="https://go.dev/doc/">Go</a>. Designed to <b>ease</b> things up for <b>fast</b> development with <a href="https://docs.gofiber.io/#zero-allocation"><b>zero memory allocation</b></a> and <b>performance</b> in mind.</em>
</p>

---
Expand Down Expand Up @@ -85,6 +85,10 @@ func main() {

This simple server is easy to set up and run. It introduces the core concepts of Fiber: app initialization, route definition, and starting the server. Just run this Go program, and visit `http://localhost:3000` in your browser to see the message.

## Zero Allocation

Fiber is optimized for **high-performance**, meaning values returned from **fiber.Ctx** are **not** immutable by default and **will** be re-used across requests. As a rule of thumb, you **must** only use context values within the handler and **must not** keep any references. Once you return from the handler, any values obtained from the context will be re-used in future requests. Visit our [documentation](https://docs.gofiber.io/#zero-allocation) to learn more.

## 🤖 Benchmarks

These tests are performed by [TechEmpower](https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=plaintext) and [Go Web](https://github.com/smallnest/go-web-framework-benchmark). If you want to see all the results, please visit our [Wiki](https://docs.gofiber.io/extra/benchmarks).
Expand Down Expand Up @@ -120,7 +124,7 @@ We **listen** to our users in [issues](https://github.com/gofiber/fiber/issues),

## ⚠️ Limitations

- Due to Fiber's usage of unsafe, the library may not always be compatible with the latest Go version. Fiber 3.0.0 has been tested with Go versions 1.21 and 1.22.
- Due to Fiber's usage of unsafe, the library may not always be compatible with the latest Go version. Fiber v3 has been tested with Go versions 1.21 and 1.22.
- Fiber is not compatible with net/http interfaces. This means you will not be able to use projects like gqlgen, go-swagger, or any others which are part of the net/http ecosystem.

## 👀 Examples
Expand Down
6 changes: 1 addition & 5 deletions docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ go get github.com/gofiber/fiber/v3
```

### Zero Allocation
Because fiber is optimized for **high-performance** care is needed when using **fiber.Ctx**:

- Some values returned from **fiber.Ctx** are **not** immutable by default, and **will** be re-used across requests.
- **fiber.Ctx** is **not** thread-safe and **must not** be accessed concurrently by multiple goroutines, the immutable setting **does not** change this.

As a rule of thumb, you **must** only use context values within the handler, and you **must not** keep any references. As soon as you return from the handler, any values you have obtained from the context will be re-used in future requests and will change below your feet. Here is an example:
Fiber is optimized for **high-performance**, meaning values returned from **fiber.Ctx** are **not** immutable by default and **will** be re-used across requests. As a rule of thumb, you **must** only use context values within the handler and **must not** keep any references. Once you return from the handler, any values obtained from the context will be re-used in future requests. Here is an example:

```go
func handler(c fiber.Ctx) error {
Expand Down

0 comments on commit 5914e92

Please sign in to comment.