Go 1.3
最後更新
Go 1.3 發布於 2014-06-18,目前最新修補版為
go1.3.3,已停止支援,請升級到 go1.27.4。版本介紹
Go 1.3 沒有語言變更,重心在實作:goroutine 堆疊改為連續堆疊(contiguous stack),垃圾回收器對堆疊上的值也變得精確,編譯器工具鏈重構讓大型專案建置更快。標準庫則新增了至今仍常用的
sync.Pool。工具
- 連結器的指令選擇階段移到編譯器(liblink),大型專案的建置速度明顯提升。
go test搭配-race時,覆蓋率模式自動設為atomic;沒有測試檔的套件也會被建置。- 支援啟用 cgo 的交叉編譯,
go run、go test新增-exec選項。 godoc新增-analysis靜態分析功能。
執行時與效能
- goroutine 堆疊從「分段」改為「連續」:空間不夠時整段搬到更大的記憶體,消除在分段邊界反覆切換的效能熱點。
- 垃圾回收器在掃描堆疊時也變精確,整數不會再被誤認為指標而讓記憶體無法回收。
- 小映射(8 個元素以下)的走訪順序重新隨機化,揪出依賴走訪順序的錯誤程式。
- 垃圾回收改用並行清掃(concurrent sweep),暫停時間可減少 50%–70%;
defer的記憶體開銷降低。 - 記憶體模型(memory model)補充說明:有緩衝的通道(channel)可以當作簡單的號誌(semaphore)使用。
標準庫重點
- 新增
sync.Pool,可重複利用暫時物件、減輕垃圾回收負擔。 testing.B新增RunParallel,方便撰寫多 CPU 並行的基準測試。crypto/tls修正可能意外略過憑證驗證的錯誤:必須設定ServerName或InsecureSkipVerify。regexp對簡單的表達式加入一次通過(one-pass)引擎,速度明顯提升。
sync.Pool
sync.Pool 像一個「暫存物件回收箱」:用完的物件放回去,下次 Get 時可能直接拿到它,省下重新配置。池裡的物件可能隨時被垃圾回收清掉,所以只適合放可以隨時重建的暫存物件,取出後也要先重設狀態。範例中的 any 是 Go 1.18 起 interface{} 的別名。- package main
- import (
- "bytes"
- "fmt"
- "sync"
- )
- var bufPool = sync.Pool{
- New: func() any {
- return new(bytes.Buffer)
- },
- }
- func render(name string) string {
- buf := bufPool.Get().(*bytes.Buffer)
- buf.Reset()
- defer bufPool.Put(buf)
- buf.WriteString("hello, ")
- buf.WriteString(name)
- return buf.String()
- }
- func main() {
- fmt.Println(render("gopher"))
- fmt.Println(render("pool"))
- }
- hello, gopher
- hello, pool
本版新增的棄用 API
本版沒有新增棄用 API。
修補版本
| 版本 | 發布日期 | 含安全修補 | 內容(官方原文) |
|---|---|---|---|
go1.3.1 | 2014-08-13 | 否 | includes bug fixes to the compiler and the runtime, net, and crypto/rsa packages. |
go1.3.2 | 2014-09-25 | 是 | includes security fixes to the crypto/tls package and bug fixes to cgo. |
go1.3.3 | 2014-09-30 | 否 | includes further bug fixes to cgo, the runtime package, and the nacl port. |
已知漏洞
在 Go 1.3 系列修補版中修正的漏洞共 1 個;仍影響最新修補版
go1.3.3 的漏洞共 213 個。本系列已修正
| 編號 | CVE | 摘要(官方原文) | 修正於 |
|---|---|---|---|
| GO-2021-0154 | CVE-2014-7189 | Man-in-the-middle attack with SessionTicketsDisabled in crypto/tls | go1.3.2 |
本版已停止支援,不會再修正這些漏洞;完整清單見 資安漏洞。