Common routines: asynchronous, de-locking, reuse, zero copy, batch, in addition to avoid premature optimization and optimize the business logic level first
1.cpu Time Optimization (Recommended Learning: Go )
make时提前预估size 临时的map、slice采用sync.Pool 大于32Kb也可用sync.Pool 不滥用goroutine,减少gc压力 不滥用mutex,减少上下文切换 []byte与string临时变量转换用unsafe 减少reflect、defer使用 atomic无锁使用
# 2. Internet IO Performance Optimization
批量接口支持 http 长连接 redis pipeline db、redis连接池 增加缓存 大量数据压缩传输
The above is the detailed content of How to optimize golang. For more information, please follow other related articles on the PHP Chinese website!