go-zero
go-zero copied to clipboard
Why don't you just use func for logic in existing frameworks?
The default code generation generates a NewXXXLogic inside the handler, which then calls the relevant methods. Why not just generate a func to call it instead of creating a new object. In highly concurrent scenarios, the creation of such a new object without adding sync.pool is likely to result in additional memory requests and destruction, which would not occur if the func was used directly.
Recommend to use sync.Pool only when you really need it.
Recommend to use
sync.Poolonly when you really need it.
The core of my question is not sync.Pool, but why the design should use oop instead of func, so there will be some performance loss, is not it? And here the struct is not a transaction that must exist, because the design itself has been designed for the monolithic service scenario to do the design of the sub-package, and for micro-services, the function is the service, there is no need to use the struct. I'm trying to understand what special considerations are involved in using such a complex technical solution that I hadn't considered before.