6
工作经验总结
source link: https://yangshuai-uestc.github.io/2022/02/25/%E5%B7%A5%E4%BD%9C%E7%BB%8F%E9%AA%8C%E6%80%BB%E7%BB%93/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
工作经验总结
01 go语言层面的一些优化
- json序列化的过程一般比较耗时,能通过其他方式解决则最好不用序列化和反序列化,序列化耗时的大头之一在于反射的过程,尤其是对于反射到
interface{}
类型的变量,会比反射到确定的类型耗时,所以能确定int
或者string
或其他类型就尽量不反射到interface{}
- go里的字符串和java一样是不可变的,代码中如果直接用
+
拼接字符串,会生成大量的字符串,尽量用sync.Pool
池化思想来复用常用的字符串,对于字符串拼接可用bytes.Buffer
结构来实现
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK