-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃 [Question]: zero allocation - why is this any different from how Chi or others behave? Can you document an example of what you mean? #3052
Comments
Thanks for opening your first issue here! 馃帀 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
@unusualevent The context object is only valid during the This is explain in detail on the documentation: https://docs.gofiber.io/#zero-allocation |
Yeah, I'm saying the documentation makes it more confusing. |
@unusualevent Here鈥檚 a simplified comparison: Fiber:
net/http based frameworks like chi, echo:
You can make Fiber's context immutable as explain in the documentation through |
Maybe I'm just dense. At least you said it in a succinct way. How would someone solve a problem differently without immutable context, compared to how they're used to doing it in net/http? |
@unusualevent As stated in the documentation: app := fiber.New(fiber.Config{
Immutable: true,
}) You can also make a single value immutable using the util functions: app.Get("/:foo", func(c *fiber.Ctx) error {
// Variable is now immutable
result := utils.CopyString(c.Params("foo"))
}) The utils have both |
Any suggestions of what we should add are welcome. The wording in the docs could use some help. |
From the fasthttp documentation (which Fiber is built upon):
Given this context, Fiber inherits these high-performance characteristics and trade-offs. The reuse of the For most developers using The immutable setting in Fiber, while available, can reduce some of the performance benefits that Fiber offers. At that point, net/http frameworks may provide similar performance without the added complexity of an immutable Fiber and its base fasthttp are tailored for specific high-performance scenarios. For many use cases, especially for developers seeking simplicity and robust community support, a net/http-based framework might be the better choice. However, for those needing extreme performance optimizations, Fiber remains a powerful and efficient option. |
Question Description
How are people re-using ctx? I don't really get that. I thought the ctx was just for DB pools that give you individual access to the DB, or for the cancellation of the program. Aren't most function contexts supposed to be local variables only (or at least dependent on a specific session?)
I'm not sure why but that throws me for a complete loop having it at the beginning of the docs. What makes code written for Fiber different from code written for Chi or similar?
Code Snippet (optional)
Checklist:
The text was updated successfully, but these errors were encountered: