AMAZINGINDEX.COM 每天一点 Amazing
58.8
VOL. 2026.11
2026.11.05
← 返回 2026.11.05 日报
日报快照 · Daily Snapshot
NO. 019

Go 1.27 重写 JSON 标准库

#ARTICLE HackerNews 2026.11.05
推荐指数 65.0 NO. 019 · 2026.11.05
发布2026/11/04Score184Comments78

Go 官方推出 encoding/json/v2 和 jsontext 新包,替代沿用 15 年的旧 API。性能提升显著且修复了长期设计缺陷,Go 生态的 JSON 处理瓶颈有望彻底改善。

旧 encoding/json 的性能问题让 Go 在微服务和高频 API 场景里长期吃亏,很多团队被迫用第三方库如 json-iterator 或 easyjson 做补丁式替换,维护成本高。v2 最大的变化是流式解析器重写和减少反射开销,benchmark 显示解码速度提升 2-5 倍,内存分配减半。

对于已经用 Go 做后端基础设施的团队,升级成本需要评估:v2 的 Marshal/Unmarshal 签名有变化,不是完全 drop-in。建议先在非关键路径做灰度,重点关注之前用 interface{} 动态解析的代码路径,那块的性能增益最明显。

意见分歧 69 条评论

核心争论:Marshal 返回 error 是否合理,编译期 vs 运行时错误之争

lolpanda

the marshal api has been very annoying. why does marshal return an error? the only reason the marshal can return an error is that the input type is not marshalable. it's certainly a code bug. to me it's like int+str returning an error instead of compiler error

hnlmorg

I wouldn’t class unmarshallable data as a compile time error. Plus the point of the marshal interface is that it’s reusable.

thayne

It could be if go had a more powerful type system.

查看原文 →